Last active
March 31, 2018 15:01
-
-
Save thesaadarshad/ccd7d34f12b3692ca5bf583c00149001 to your computer and use it in GitHub Desktop.
python datetime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
now = datetime.datetime.now() | |
print "Current date and time using str method of datetime object:" | |
print str(now) | |
print "Current date and time using instance attributes:" | |
print "Current year: %d" % now.year | |
print "Current month: %d" % now.month | |
print "Current day: %d" % now.day | |
print "Current hour: %d" % now.hour | |
print "Current minute: %d" % now.minute | |
print "Current second: %d" % now.second | |
print "Current microsecond: %d" % now.microsecond | |
print "Current date and time using strftime:" | |
print now.strftime("%Y-%m-%d %H:%M") | |
print "Current date and time using isoformat:" | |
print now.isoformat() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment