Get time and date – python

#! /usr/bin/env python
#
# How to get the current date and do some simple formatting
# For more info see http://docs.python.org/lib/module-datetime.html
#

import datetime

today     = datetime.datetime.today()
print today

rightnow  = datetime.datetime.now()
print rightnow

todaystring = datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")
print todaystring
2006-07-10 21:26:05.234935
2006-07-10 21:26:05.235828
2006-07-10 21:26:05
blog comments powered by Disqus