Python 日期和时间
来源:互联网 发布:商家请淘宝介入退款 编辑:程序博客网 时间:2024/06/05 06:20
什么是Tick?
#!/usr/bin/pythonimport time; # This is required to include time module.print "Number of ticks since 12:00am, January 1, 1970:", ticks
Number of ticks since 12:00am, January 1, 1970: 7186862.73399
什么是时间元组?
5秒0到61 (60或61 是闰秒)6一周的第几日0到6 (0是周一)7一年的第几日1到366 (儒略历)8夏令时-1, 0, 1, -1是决定是否为夏令时的旗帜
获取当前时间
#!/usr/bin/pythonimport time;print "Local current time :", localtime
Local current time : time.struct_time(tm_year=2013, tm_mon=7, tm_mday=17, tm_hour=21, tm_min=26, tm_sec=3, tm_wday=2, tm_yday=198, tm_isdst=0)
获取格式化的时间
#!/usr/bin/pythonimport time;print "Local current time :", localtime
Local current time : Tue Jan 13 10:17:09 2009
获取某月日历
#!/usr/bin/pythonprint "Here is the calendar:"print cal;
Here is the calendar: January 2008Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 1314 15 16 17 18 19 2021 22 23 24 25 26 2728 29 30 31
Time模块
返回格林威治西部的夏令时地区的偏移秒数。如果该地区在格林威治东部会返回负值(如西欧,包括英国)。对夏令时启用地区才能使用。2time.asctime([tupletime])
接受时间元组并返回一个可读的形式为"Tue Dec 11 18:07:14 2008"(2008年12月11日 周二18时07分14秒)的24个字符的字符串。3time.clock( )
用以浮点数计算的秒数返回当前的CPU时间。用来衡量不同程序的耗时,比time.time()更有用。4time.ctime([secs])
作用相当于asctime(localtime(secs)),未给参数相当于asctime()5time.gmtime([secs])
接收时间辍(1970纪元后经过的浮点秒数)并返回格林威治天文时间下的时间元组t。注:t.tm_isdst始终为06time.localtime([secs])
接收时间辍(1970纪元后经过的浮点秒数)并返回当地时间下的时间元组t(t.tm_isdst可取0或1,取决于当地当时是不是夏令时)。7time.mktime(tupletime)
接受时间元组并返回时间辍(1970纪元后经过的浮点秒数)。8time.sleep(secs)
推迟调用线程的运行,secs指秒数。9time.strftime(fmt[,tupletime])
接收以时间元组,并返回以可读字符串表示的当地时间,格式由fmt决定。10time.strptime(str,fmt='%a %b %d %H:%M:%S %Y')
根据fmt的格式把一个时间字符串解析为时间元组。11time.time( )
返回当前时间的时间戳(1970纪元后经过的浮点秒数)。12time.tzset()
根据环境变量TZ重新初始化时间相关设置。
属性time.timezone是当地时区(未启动夏令时)距离格林威治的偏移秒数(>0,美洲;<=0大部分欧洲,亚洲,非洲)。2time.tzname
属性time.tzname包含一对根据情况的不同而不同的字符串,分别是带夏令时的本地时区名称,和不带的。
日历(Calendar)模块
返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c。 每日宽度间隔为w字符。每行长度为21* W+18+2* C。l是每星期行数。2calendar.firstweekday( )
返回当前每周起始日期的设置。默认情况下,首次载入caendar模块时返回0,即星期一。3calendar.isleap(year)
是闰年返回True,否则为false。4calendar.leapdays(y1,y2)
返回在Y1,Y2两年之间的闰年总数。5calendar.month(year,month,w=2,l=1)
返回一个多行字符串格式的year年month月日历,两行标题,一周一行。每日宽度间隔为w字符。每行的长度为7* w+6。l是每星期的行数。6calendar.monthcalendar(year,month)
返回一个整数的单层嵌套列表。每个子列表装载代表一个星期的整数。Year年month月外的日期都设为0;范围内的日子都由该月第几日表示,从1开始。7calendar.monthrange(year,month)
返回两个整数。第一个是该月的星期几的日期码,第二个是该月的日期码。日从0(星期一)到6(星期日);月从1到12。8calendar.prcal(year,w=2,l=1,c=6)
相当于 print calendar.calendar(year,w,l,c).9calendar.prmonth(year,month,w=2,l=1)
相当于 print calendar.calendar(year,w,l,c)。10calendar.setfirstweekday(weekday)
设置每周的起始日期码。0(星期一)到6(星期日)。11calendar.timegm(tupletime)
和time.gmtime相反:接受一个时间元组形式,返回该时刻的时间辍(1970纪元后经过的浮点秒数)。12calendar.weekday(year,month,day)
返回给定日期的日期码。0(星期一)到6(星期日)。月份为 1(一月) 到 12(12月)。
0 0
- python 时间和日期
- Python 日期和时间
- Python 日期和时间
- Python 日期和时间
- Python日期和时间
- python日期和时间
- Python 日期和时间
- python日期和时间
- python时间和日期
- Python 日期和时间
- Python日期和时间
- Python日期和时间
- Python 日期和时间
- Python 日期和时间
- Python 日期和时间
- Python 日期和时间
- Python 日期和时间
- Python 日期和时间
- 据说有99%的人都会做错的面试题
- LabVIEW上位机与串口通信
- 输入框 js正则判断输入
- 坚持每天写一个程序
- CentOS配置smaba与Windows共享文件
- Python 日期和时间
- 三极管的电平转换及驱动电路分析
- LeetCode-Binary Tree Level Order Traversal II
- Validate Binary Search Tree
- 对功率谱的一点理解
- valuestack的工作原理
- C#中的json格式字符串解析
- 数组的指针特性
- RTF转纯文本