Python 日期和时间的几种输出格式,,在python中,我
Python 日期和时间的几种输出格式,,在python中,我
在python中,我们可以使用 time 模块的 strftime 方法来格式化日期,例子如下:
import time# 格式化成2016-03-20 11:45:39形式print (time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))# 格式化成Sat Mar 28 22:24:24 2016形式print (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime())) # 将格式字符串转换为时间戳a = "Sat Mar 28 22:24:24 2016"print (time.mktime(time.strptime(a,"%a %b %d %H:%M:%S %Y")))
输出结果为:
2017-10-07 09:27:14Sat Oct 07 09:27:14 20171459175064.0***Repl Closed***
如下是一些python中时间日期格式化符号:
Python 日期和时间的几种输出格式
相关内容
- Python 练习一(计算1-2+3-4...+99),,# 求1-99的所有
- Python中的int(x,base)函数,,ython中的int
- Python的Pandas库简述,,pandas 是 p
- QT调用python的部分问题,,环境qt5.9.0+
- Python面向对象的三大属性,,一、封装1、封装的介
- python中split()和split(' ')的区别,,总结:sp
- 循环卷积python代码,, 最近舍友要写一份与
- python 除法,,在python-2中
- Python中利用for表达式创建列表,,1、for表达式语法
- python鐨刦rame鍒囨崲,,鏍囩锛?a hre
评论关闭