首页 > 其他 > 详细

常用模块

时间:2020-08-01 14:26:20      阅读:78      评论:0      收藏:0      [点我收藏+]

一、time模块

import time

# s = time.time()
# print(s)
# time.sleep(2)

# 拿到format string的方式
# print(time.ctime(s))   # time.ctime(float) ----> format string in local time
# print(time.asctime(time.localtime(s)))    # time.asctime(tuple) ----> format string in local time
# print(time.asctime())    # 如果不传值,默认的就会用当前的时间戳
# print(time.ctime())    # 如果不传值,默认的就会用当前的struct time
# print(time.localtime())

# print(time.strftime(‘%Y-%m-%d %H:%M:%S‘, time.localtime()))    # 按照给定的格式 将 tuple---> string。 strptime  是 string parse time 的缩写,就是将字符串解析成元组的意思。
 

Commonly used format codes:

%Y Year with century as a decimal number.
%m Month as a decimal number [01,12].
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%M Minute as a decimal number [00,59].
%S Second as a decimal number [00,61].
%z Time zone offset from UTC.
%a Locale‘s abbreviated weekday name.
%A Locale‘s full weekday name.
%b Locale‘s abbreviated month name.
%B Locale‘s full month name.
%c Locale‘s appropriate date and time representation.
%I Hour (12-hour clock) as a decimal number [01,12].
%p Locale‘s equivalent of either AM or PM.



# 拿到时间戳 float 类型
# tu = time.localtime()
# print(tu)
# s = time.mktime(tu)    # time.mktime() 将 tuple----> float
# print(time.time())

# 拿到struct time 类型
# s = time.time()
# print(time.localtime(s))   # 北京时间 接受float ---> tuple
# print(time.gmtime(s))   # 天文台时间 接受float ---> tuple

The other representation is a tuple of 9 integers giving local time.
The tuple items are:
year (including century, e.g. 1998)
month (1-12)
day (1-31)
hours (0-23)
minutes (0-59)
seconds (0-59)
weekday (0-6, Monday is 0)
Julian day (day in the year, 1-366)
DST (Daylight Savings Time) flag (-1, 0 or 1)
If the DST flag is 0, the time is given in the regular time zone;
if it is 1, the time is given in the DST time zone;
if it is -1, mktime() should guess based on the date and time.



# print(time.strptime(time.ctime()))   # 接受 string ---> tuple。 strftime 是 string format time 的缩写  就是转成字符串时间的意思
# print(time.strptime(time.asctime()))   # 接受 string ---> tuple

 技术分享图片

 

 

常用模块

原文:https://www.cnblogs.com/Teyisang/p/13414187.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!