wzpan
8/20/2013 - 12:07 PM

Python - timestamp

Python - timestamp

import datetime

# 2012-12-15 10:14:51.898000
print datetime.datetime.utcnow()

# The now differs from utcnow as expected
# otherwise they work the same way:
# 2012-12-15 11:15:09.205000
print datetime.datetime.now()

# You can render the timestamp to the ISO format string explicitly:
# '2012-12-15 11:15:24.984000'
str(datetime.datetime.now())

# Or you can be even more explicit to format the
# timestamp the way you like:

# 'Saturday, 15. December 2012 11:19AM'
datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p")
# '2012-12-15'
datetime.datetime.now().strftime("%Y-%m-%d")