strftime和strptime函数均来自包datetime

from datetime import *

strftime:

将datetime包中的datetime类,按照入参格式生成字符串变量

from datetime import *
currenttime=datetime.now() #生成当前时间的datetime类实例
print('type of currenttime', type(currenttime))
print(currenttime)
cur=currenttime.strftime('%Y_%m_%d-%H-%M-%S')
print('type of cur', type(cur))
print(cur)

输出

type of currenttime <class 'datetime.datetime'>
2019-08-29 14:01:39.973547
type of cur <class 'str'>
2019_08_29-14-01-39

strptime:

将字符串根据其格式,提取所含时间,并生成datetime类实例

from datetime import *
strdate='2019:08:29:09-00-00'
strdatetime=datetime.strptime(strdate,'%Y:%m:%d:%H-%M-%S')
print('type of strdatetime:',type(strdatetime),':',strdatetime)

输出

type of strdatetime: <class 'datetime.datetime'> : 2019-08-29 09:00:00

注意:strptime中的第二个参数是输入字符串的格式,而不是出参格式,datetime实例的格式是固定的

最新文章

  1. css的margin
  2. grunt 单独压缩多个js和css文件【转】
  3. jQuery-1.9.1源码分析系列(八) 属性操作
  4. mysql 联合查询后update
  5. Java中将0x开头的十六进制字符串转换成十进制整数
  6. 精通jQuery选择器
  7. VirtualBox clonevdi文件和修改vdi的uuid
  8. Jersey(1.19.1) - Hello World, Get started with Jersey using the embedded Grizzly server
  9. 学习xcode 博客
  10. C# 运算符 if
  11. linux之多进程fork:进程通信
  12. Win10系统下的Tomcat7.0配置
  13. 研究大华3G设备接入自主视频开发平台
  14. 1.PHP连接mysql
  15. Python网络编程Socket之协程
  16. start-dfs.sh 启动成功 datanode未启动
  17. python简说(八)random
  18. Java之Map的使用场景
  19. Python基础学习笔记,进阶学习笔记 出处
  20. JSTL的一些使用规范,坑

热门文章

  1. ObjectDataSource.ObjectCreating 事件
  2. windows 开启/关闭本地连接的批处理程序
  3. Pytorch搭建卷积神经网络用于MNIST分类
  4. 13.DoS防御----BeEF浏览器渗透----暴力破解之美杜莎---DNS指南
  5. linux/linux学习笔记-Shell基础(mooc)
  6. Springboot2.x集成Redis哨兵模式
  7. python 三元表达式
  8. glVertexAttribPointer 顶点数据解析方式
  9. 本地代码推送到远程git仓库
  10. linux-memcache安装及memcached memcache扩展