Skip to content

Instantly share code, notes, and snippets.

@01x01
Created January 31, 2019 12:34
Show Gist options
  • Save 01x01/865c97a4a9083f78b19a0ef405ad4975 to your computer and use it in GitHub Desktop.
Save 01x01/865c97a4a9083f78b19a0ef405ad4975 to your computer and use it in GitHub Desktop.
Symbol Meaning Example
%a Abbreviated weekday name 'Wed'
%A Full weekday name 'Wednesday'
%w Weekday number: 0 (Sunday) through 6 (Saturday) '3'
%d Day of the month (zero padded) '13'
%b Abbreviated month name 'Jan'
%B Full month name 'January'
%m Month of the year '01'
%y Year without century '18'
%Y Year with century '2018'
%H Hour from 24-hour clock '17'
%I Hour from 12-hour clock '05'
%p AM/PM 'PM'
%M Minutes '00'
%S Seconds '00'
%f Microseconds '000000'
%z UTC offset for time zone–aware objects '-0500'
%Z Time zone name 'EST'
%j Day of the year '013'
%W Week of the year '02'
%c Date and time representation for the current locale 'Wed Jan 13 17:00:00 2016'
%x Date representation for the current locale '01/13/16'
%X Time representation for the current locale '17:00:00'
%% A literal % character '%'
# GMT 时间格式
GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
# 时间对象 转字符串
from datetime import datetime
datetime.strftime(datetime.now(),"%Y-%m-%d %H:%M:%S")
# 字符串对象转时间对象
from datetime import datetime
>>> datetime.strptime('2018-09-09',"%Y-%m-%d")
datetime.datetime(2018, 9, 9, 0, 0)
# 美国时间 和 UTC 时间 转换
datetime.strftime(datetime.utcnow()-timedelta(hours=8),'%Y-%m-%d %H:%M:%S')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment