Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # module_datetime.py
- import datetime
- now = datetime.datetime.now()
- print
- print "Current date and time using str method of datetime object:"
- print str(now)
- print
- print "Current date and time using instance attributes:"
- print "Current year: %d" % now.year
- print "Current month: %d" % now.month
- print "Current month by name:", now.strftime("%B")
- print "Current day: %d" % now.day
- print "Current day by name:", now.strftime("%A")
- 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
- print "Current date and time using strftime:"
- print now.strftime("%Y-%m-%d %H:%M %p")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement