Python时间转换
来源:互联网 发布:优化glsl着色器 编辑:程序博客网 时间:2024/06/06 02:33
要得到年月日时分秒的时间:
import time#time.struct_time(tm_year=2012, tm_mon=9, tm_mday=15, tm_hour=15, tm_min=1, tm_sec=44, tm_wday=5, tm_yday=259, tm_isdst=0)print time.localtime() #返回tuple#2012-09-15 15:01:44print time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())#2012-09-15 03PM 01:44 今天是当年第259天 当年第37周 星期6print time.strftime("%Y-%m-%d %I%p %M:%S 今天是当年第%j天 当年第%U周 星期%w",time.localtime())#1347692504.41 [秒数]:doubleprint time.time()#指令 含义 # #%Y 有世纪的年份,如2012#%m 十进制月份[01,12]. #%d 当月的第几天 [01,31]. #%H 24进制的小时[00,23]. #%M 十进制分钟[00,59]. #%S 秒数[00,61]. 61是有闰秒的情况 ##%w 十进制的数字,代表周几 ;0是周日,1是周一.. [0(Sunday),6]. ##%I 十二进制的小时[01,12]. #%p 上午还是下午: AM or PM. (1) ##%j 当年第几天[001,366]. #%U 当年的第几周[00,53] 0=新一年的第一个星期一之前的所有天被认为是在0周【周日是每周第一天】#%W 当年的第几周[00,53] 0=新一年的第一个星期一之前的所有天被认为是在0周【周一是每周第一天】# #%y 无世纪的年份[00,99]. 如12年
2.格式转换
#============================
# 时间格式time的方法:
# localtime(秒数) # :秒数-->time.struct_time
# mktime(time.struct_time) #:time.struct_time-->秒数
# strftime("格式串",time.struct_time) #:time.struct_time -->"yyyy-mm-dd HH:MM:SS"
# strptime(tuple_日期,"格式串") #:"yyyy-mm-dd HH:MM:SS"-->time.struct_time
#============================
# 1. 秒数 ->[tuple]-> 年月日串
birth_secds = 485749800
tup_birth = time.localtime(birth_secds)
format_birth = time.strftime("%Y-%m-%d %H:%M:%S",tup_birth)
# 2. 年月日串 ->[tuple]-> 秒数
print format_birth#1985-05-24 10:30:00
format_birth = "1985-05-24 10:30:00"
tup_birth = time.strptime(format_birth, "%Y-%m-%d %H:%M:%S");
birth_secds = time.mktime(tup_birth)
print birth_secds#485749800.0
- python-时间戳转换时间
- python时间转换
- python 时间转换函数
- python 时间转换应用
- Python中的时间转换
- Python的时间转换
- python时间日期转换
- Python:时间戳转换
- python 时间转换
- Python时间转换
- python 时间转换
- python 中英文时间转换
- python 时间格式转换
- python 时间格式转换
- python 字符串和时间转换
- python的时间戳转换
- python 时间字符串格式转换
- Unix时间戳转换(python)
- 深度学习UFLDL教程翻译之BP算法
- At Commands:从白痴到大师的修炼历程(一)
- MxNet : use the MxNet windows versioin
- 眼睛区域提取研究
- 注解方式配置Spring实现Ioc
- Python时间转换
- Android 调用系统相册选择图片并显示
- 四大组件Service的工作过程
- C++笔记
- Cf 364div2 [C.尺取法]
- 关于ionic中popup在Android中多次按返回键弹出多次的解决方法
- Python3爬虫学习笔记1.0——什么是爬虫?
- 获取ntoskrnl的基址
- 【内蒙古&山西の游记(7.17~7.24)】二周目