Riju21

23_datetime

Mar 29th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. # data & time
  2. import datetime
  3. import pytz       # python timezone library
  4. # basic date
  5. # ---------------------------------
  6.  
  7. dat1 = datetime.date.today()    # current date
  8. print(dat1)                     # full date
  9. # print(dat1.day)               # current day
  10. # print(dat1.year)              # current year
  11. # print(dat1.month)             # current month
  12.  
  13. # weekday vs, isoweekday
  14. # ---------------------------
  15.     # week from 0-6 & isoweek from 1-7
  16. # print(dat1.weekday())
  17. # print(dat1.isoweekday())
  18.  
  19. # adding & subtracting date
  20. # ---------------------------
  21.  
  22. # sevenDays = datetime.timedelta(days=7)
  23. # print('seven days later: ', dat1 + sevenDays)
  24. # print('seven days back: ', dat1 - sevenDays)
  25.  
  26. # simple example: total days from birthday
  27.  
  28. # myBirth = datetime.date(2018, 12, 8)
  29. # dayCount = myBirth - dat1
  30. # print(dayCount.days)  # only days
  31. # print(dayCount.total_seconds())  # only sec
  32.  
  33.  
  34. # python time zone
  35. # -------------------------
  36.  
  37. # dateTimee = datetime.datetime(2018, 9, 6, 7, 26, 40, tzinfo=pytz.UTC)
  38. # print(dateTimee)
  39. dateTimee_now = datetime.datetime.now(tz=pytz.UTC)
  40. # print(dateTimee_now)
  41. myZone = dateTimee_now.astimezone(pytz.timezone('Etc/GMT +6.0'))
  42. # print(myZone)
  43. # print all timezone
  44. # -----------------------
  45. # for tz in pytz.all_timezones:
  46. #     print(tz)
Advertisement
Add Comment
Please, Sign In to add comment