Created
December 31, 2017 07:38
-
-
Save vladwa/8cd97099e32c1088025dfaca5f1bfd33 to your computer and use it in GitHub Desktop.
Python snippet to get the PST time and date.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from pytz import timezone | |
def get_pst_time(): | |
date_format='%m_%d_%Y_%H_%M_%S_%Z' | |
date = datetime.now(tz=pytz.utc) | |
date = date.astimezone(timezone('US/Pacific')) | |
pstDateTime=date.strftime(date_format) | |
return pstDateTime |
Pacific time is different from PST. It switches to PST or PDT according to date.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
after import pytz not show the time so change return function print function then saw the time
from datetime import datetime
from pytz import timezone
import pytz
def get_pst_time():
date_format='%m_%d_%Y_%H_%M_%S_%Z'
date = datetime.now(tz=pytz.utc)
date = date.astimezone(timezone('US/Pacific'))
pstDateTime=date.strftime(date_format)
print(pstDateTime)
Thankyou