Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # data & time
- import datetime
- import pytz # python timezone library
- # basic date
- # ---------------------------------
- dat1 = datetime.date.today() # current date
- print(dat1) # full date
- # print(dat1.day) # current day
- # print(dat1.year) # current year
- # print(dat1.month) # current month
- # weekday vs, isoweekday
- # ---------------------------
- # week from 0-6 & isoweek from 1-7
- # print(dat1.weekday())
- # print(dat1.isoweekday())
- # adding & subtracting date
- # ---------------------------
- # sevenDays = datetime.timedelta(days=7)
- # print('seven days later: ', dat1 + sevenDays)
- # print('seven days back: ', dat1 - sevenDays)
- # simple example: total days from birthday
- # myBirth = datetime.date(2018, 12, 8)
- # dayCount = myBirth - dat1
- # print(dayCount.days) # only days
- # print(dayCount.total_seconds()) # only sec
- # python time zone
- # -------------------------
- # dateTimee = datetime.datetime(2018, 9, 6, 7, 26, 40, tzinfo=pytz.UTC)
- # print(dateTimee)
- dateTimee_now = datetime.datetime.now(tz=pytz.UTC)
- # print(dateTimee_now)
- myZone = dateTimee_now.astimezone(pytz.timezone('Etc/GMT +6.0'))
- # print(myZone)
- # print all timezone
- # -----------------------
- # for tz in pytz.all_timezones:
- # print(tz)
Advertisement
Add Comment
Please, Sign In to add comment