Created
October 1, 2022 12:34
-
-
Save 0187773933/86464bf1c4aabbb03ecb5c140fc977e1 to your computer and use it in GitHub Desktop.
Get Common Time String in Python
This file contains hidden or 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
import datetime | |
from pytz import timezone # pip install pytz | |
# print( pytz.country_timezones[ "US" ] ) | |
def get_common_time_string( time_zone=timezone( "US/Eastern" ) ): | |
now = datetime.datetime.now().astimezone( self.timezone ) | |
milliseconds = round( now.microsecond / 1000 ) | |
milliseconds = str( milliseconds ).zfill( 3 ) | |
now_string = now.strftime( "%d%b%Y === %H:%M:%S" ).upper() | |
return f"{now_string}.{milliseconds}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment