# Chapter11.py # log_datetime.txt # imports import datetime # datetime.datetime # from datetime import datetime,date,time,timedelta #datetime # DateTime Class Page 305 # datetime type (string,int,boolean) # 5 primary objects in datetime ## datetime.date -> (year, month, day) ## datetime.time -> (hour,minute,second,microsecond) ## datetime.datetime -> (yr,mon,day,hr,mi,sec,micro) ## datetime.timedelta -> differences in dates ## datetime.tzinfo -> utc time zone # Current date and time using now() currentDateTime = datetime.datetime.now() print(f"Current DateTime Stamp: {currentDateTime}") # 2024-08-02 12:33:37.521654 <--- datetime type # Current Date today = datetime.date.today() print(f"Today's date: {today}") # 2024-08-02 00:00:00.000000 # Birthday print("Birthday Form") varMonth = input("Month (mm): ") # string varDay = input("Day (dd): ") # string varYear = input("Year (yyyy): ") # string birthday = datetime.datetime(int(varYear),int(varMonth),int(varDay)) print(f"Birthday: {birthday}") # Datetime Formatting page 309 # Friday August 2, 2024 # %A %B %d, %Y 03 21 1990 print(f"Birthday: {birthday:%A %B %d, %Y}") # Wednesday March 21, 1990 # timedelta to calculate differences in time invoiceDate = datetime.datetime.now() terms = 30 # Net30 due dueDate = invoiceDate + datetime.timedelta(days=terms) print(f"Invoice Due Date: {dueDate:%A %B %d, %Y}") # import locale import locale # locale setting EST - PST # Get the datetime with UTC from datetime import timezone nowUTC = datetime.datetime.now(timezone.utc) print(nowUTC) # convert to another time zone ## Create a variable to adjust for timedelta(hours=-4) pst = timezone(datetime.timedelta(hours=-4)) # EST -4 PST pstNow = nowUTC.astimezone(pst) print(pstNow)