1. Ways to take the past specific time:
Copy Code code as follows:
#!/usr/bin/python
Import time
#取一天前的当前具体时间
Time.strftime ('%y-%m-%d%T ', Time.localtime (Time.time () -24*60*60))
#取15天前的当前具体时间
Time.strftime ('%y-%m-%d%T ', Time.localtime (Time.time () -15*24*60*60))
#取15天前当前具体时间的前2小时
Time.strftime ('%y-%m-%d%T ', Time.localtime (Time.time () -15*24*60*60-2*60*60))
2. Ways to take future time:
Copy Code code as follows:
#!/usr/bin/python
Import time
#取一天后的当前具体时间
Time.strftime ('%y-%m-%d%T ', Time.localtime (Time.time () +24*60*60))
#取20天后的当前具体时间
Time.strftime ('%y-%m-%d%T ', Time.localtime (Time.time () +20*24*60*60))
#取20天后当前具体时间的前2小时
Time.strftime ('%y-%m-%d%T ', Time.localtime (Time.time () +20*24*60*60-2*60*60))
3. To take only a certain time unit past, future specific values:
Copy Code code as follows:
#!/usr/bin/python
Import time
#取上一月月份
Time.localtime () [1]-1
#取去年年份
Time.localtime () [0]-1
#取两个月后的月份
Time.localtime () [1]+2
Time.strftime () Format command:
Copy Code code as follows:
%a Day of the week
%A the full name of the week
%b of the Month
Full name of%B month
Time series for the%c standard date
Rear two digits of%c year
The first day of the month in%d decimal notation
%d Month/day/year
%e in a two-character field, the first day of the month in decimal notation
%F year-month-day
Two digits of%g year, using week-based years
%G years, using weeks based
%h Abbreviated month name
%H 24-hour system hours
%I 12-hour hours
%j decimal representation of the first day of the year
Month in%m decimal notation
Number of minutes represented by%m 10 o'clock
%n New Line character
%p the equivalent display of a local AM or PM
%r 12 hours.
%R display hours and minutes: hh:mm
%s decimal number of seconds
%t Horizontal Tab
%T when displayed: Hh:mm:ss
%u days of the week, Monday is the first day (values from 0 to 6, Monday to 0)
%u week of the year, make Sunday the first day (values from 0 to 53)
%V the first weeks of the year, using a week based year
%w decimal representation of the week (values from 0 to 6, Sunday to 0)
%w Week of the year, Monday is the first day (value from 0 to 53)
The date string of the%x standard
%x Standard Time series
%y decimal Year without century (values from 0 to 99)
%Y 10 year of the century part
%z,%z the time zone name and returns a null character if the time zone name cannot be obtained.
Percent percent%