Python novice. How to add CST/DST

Posted on
Sat Feb 06, 2021 7:27 am
TomJ offline
Posts: 8
Joined: Nov 08, 2009
Location: Midwest

Python novice. How to add CST/DST

Python novice, REAL Python novice
How do I add “CST” or “CDT” (US central time) to make the result:
---Time is: Sat Feb-06-21 @ 07:25:14 AM CST
There doesn’t seem to be formatting code for this


from datetime import datetime
import pytz

# get the standard UTC time
UTC = pytz.utc

# get the time zone of the specified location
IST = pytz.timezone('America/Chicago')

#print the date and time in specified format
datetime_ist = datetime.now(IST)
print("Time is:",datetime_ist.strftime('%a %b-%d-%y @ %I:%M:%S %p'))

THANKS

Posted on
Sat Feb 06, 2021 7:52 am
FlyingDiver offline
User avatar
Posts: 7211
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python novice. How to add CST/DST

Code: Select all
from datetime import datetime
import pytz

# get the time zone of the specified location
IST = pytz.timezone('America/Chicago')

#print the date and time in specified format
datetime_ist = datetime.now(IST)
print "Time is: " + datetime_ist.strftime('%a %b-%d-%y @ %I:%M:%S %p %Z')

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests