Advertisement
codecaine

date time format examples

Jul 14th, 2021
1,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. from datetime import datetime
  2.  
  3. dt = datetime.now()
  4.  
  5. print(dt)
  6. print('\nDirectives\n--------------')
  7. print(dt.strftime('Weekday short version : %a'))
  8. print(dt.strftime('Weekday full version  : %A'))
  9. print(dt.strftime('Weekday as a number   : %w'))
  10. print(dt.strftime('Day of month          : %d'))
  11. print(dt.strftime('Month Name short ver  : %d'))
  12. print(dt.strftime('Month Name full ver   : %b'))
  13. print(dt.strftime('Month as a number     : %m'))
  14. print(dt.strftime('Year short version    : %y'))
  15. print(dt.strftime('Year full version     : %Y'))
  16. print(dt.strftime('Hour (00-23)          : %H'))
  17. print(dt.strftime('Hour (00-11)          : %I'))
  18. print(dt.strftime('AM/PM                 : %p'))
  19. print(dt.strftime('Minute                : %M'))
  20. print(dt.strftime('Second                : %S'))
  21.  
  22.  
  23. print('\nFormatted Date Strings\n--------------')
  24. print(dt.strftime('%a %d-%m-%Y'))
  25. print(dt.strftime('%a %d/%m/%Y'))
  26. print(dt.strftime('%a %d/%m/%y'))
  27. print(dt.strftime('%A %d-%m-%Y, %H:%M:%S'))
  28. print(dt.strftime('%X %x'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement