Skip to content

Instantly share code, notes, and snippets.

@0187773933
Created October 1, 2022 12:34
Show Gist options
  • Save 0187773933/86464bf1c4aabbb03ecb5c140fc977e1 to your computer and use it in GitHub Desktop.
Save 0187773933/86464bf1c4aabbb03ecb5c140fc977e1 to your computer and use it in GitHub Desktop.
Get Common Time String in Python
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