Print current time

from datetime import datetime'%Y-%m-%d %H:%M:%S')
# '2015-12-29 14:02:27'

Get current time

import datetime
# datetime(2009, 1, 6, 15, 8, 24, 78915)


import time

Measure time elapsed

import time

start = time.time()
end = time.time()
print(end - start)


Dealing with dates in Python shouldn't have to suck.


pip install moment


import moment
from datetime import datetime

# Create a moment from a string"12-18-2012")

# Create a moment with a specified strftime format"12-18-2012", "%m-%d-%Y")

# Moment uses the awesome dateparser library behind the scenes"2012-12-18")

# Create a moment with words in it"December 18, 2012")

# Create a moment that would normally be pretty hard to do"2 weeks ago")

# Create a future moment that would otherwise be really difficult"2 weeks from now")

# Create a moment from the current datetime

# The moment can also be UTC-based

# Create a moment with the UTC time zone

# Create a moment from a Unix timestamp

# Create a moment from a Unix UTC timestamp
moment.unix(1355875153626, utc=True)

# Return a datetime instance, 12, 18).date

# We can do the same thing with the UTC method
moment.utc(2012, 12, 18).date

# Create and format a moment using Moment.js semantics"YYYY-M-D")

# Create and format a moment with strftime semantics, 12, 18).strftime("%Y-%m-%d")

# Update your moment's time zone, 12, 18)).locale("US/Central").date

# Alter the moment's UTC time zone to a different time zone

# Set and update your moment's time zone. For instance, I'm on the
# west coast, but want NYC's current time."US/Pacific").timezone("US/Eastern")

# In order to manipulate time zones, a locale must always be set or
# you must be using UTC.

# You can also clone a moment, so the original stays unaltered
now = moment.utcnow().timezone("US/Pacific")
future = now.clone().add(weeks=2)