#python
import time
import datetime
#only date
today = datetime.date.today()
#now time, including date and time
now = datetime.datetime.now()
#UTC now time, including date and time
utcnow = datetime.datetime.utcnow()
#ctime() standard time output string
print now.ctime()
#Thu Feb 26 17:50:55 2009
#strftime() (string-format time) format the output string
print now.strftime("%A %B %d %I:%M:%S %p %Y")
#Thursday Febuary 14 05:50:55 PM 2009
import time
import datetime
#only date
today = datetime.date.today()
#now time, including date and time
now = datetime.datetime.now()
#UTC now time, including date and time
utcnow = datetime.datetime.utcnow()
#ctime() standard time output string
print now.ctime()
#Thu Feb 26 17:50:55 2009
#strftime() (string-format time) format the output string
print now.strftime("%A %B %d %I:%M:%S %p %Y")
#Thursday Febuary 14 05:50:55 PM 2009
For more example, please read Dates and Times
datetime — Basic date and time types
沒有留言:
張貼留言