Python time and date

  • %y Two-digit year representation (00-99)
  • %Y Four-digit year representation (000-9999)
  • %m month (01-12)
  • %d day of the month (0-31)
  • %H 24-hour hour (0-23)
  • %I 12-hour clock (01-12)
  • %M minutes (00=59)
  • %S seconds (00-59)
  • %a local abbreviated weekday name
  • %A local full week name
  • %b local abbreviated month name
  • %B local full month name
  • %c Local corresponding date representation and time representation
  • Day of the year in %j (001-366)
  • %p local AM or PM equivalent
  • %U Week of the year (00-53) Sunday is the start of the week
  • %w week (0-6), Sunday is the start of the week
  • %W Week of the year (00-53) Monday is the start of the week
  • %x local corresponding date representation
  • %X local corresponding time representation
  • %Z The name of the current time zone
  • %%% sign itself
#coding=utf-8
import time
#get timestamp
ticket=time.time()
print ticket
#Get current time
localtime=time.localtime(ticket)
print 'Current time:', localtime
#Format time
astime=time.asctime(localtime)
print astime
#custom format time
print time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
#Uppercase is the full name, lowercase is the abbreviation
print time.strftime("%A-%B-%d %H:%M:%S",time.localtime())


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325517931&siteId=291194637