Advertisement
here2share

# module_datetime.py

Apr 10th, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. # module_datetime.py
  2.  
  3. import datetime
  4.  
  5. now = datetime.datetime.now()
  6.  
  7. print
  8. print "Current date and time using str method of datetime object:"
  9. print str(now)
  10.  
  11. print
  12. print "Current date and time using instance attributes:"
  13. print "Current year: %d" % now.year
  14. print "Current month: %d" % now.month
  15. print "Current month by name:", now.strftime("%B")
  16. print "Current day: %d" % now.day
  17. print "Current day by name:", now.strftime("%A")
  18. print "Current hour: %d" % now.hour
  19. print "Current minute: %d" % now.minute
  20. print "Current second: %d" % now.second
  21. print "Current microsecond: %d" % now.microsecond
  22.  
  23. print
  24. print "Current date and time using strftime:"
  25. print now.strftime("%Y-%m-%d %H:%M %p")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement