Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

time zone

>>> import pytz
>>> from datetime import datetime, date, time
# To get the UTC time of current day (today) for a given time zone
# use the localize() function of the pytz. 
# The reason for this is that the localize() takes into account the Day Time Saving
# which niether the datetime constructors nor replace() account for.
# 
# To for example, the utc time of today in australia time zone:

import pytz
from datetime import datetime, date, time

# set time zone
tz = pytz.timezone("Australia/Melbourne")

# Get today's date in the current time zone (i.e local time)
todaydate = date.today() # you can also use date(2022, 2, 8)

# Get midnight of today (still local time)
# note time() without arguments will result to midnight

midnight_local = datetime.combine(todaydate, time())

print midnight_local

# convert this midnight datetime to the midnight datetime
# in the given time zone. In this case autralia time zone
austra_midnight = tz.localize(midnight_local)

print austra_midnight

# convert the midnight time in australia time zone to UTC
midnight_austra_utc = austra_midnight.astimezone(pytz.uct)

print midnight_austra_utc



# Ref:
# https://stackoverflow.com/questions/373370/how-do-i-get-the-utc-time-of-midnight-for-a-given-timezone
Comment

timezone

' check time zone
DateDiff("s", "01/01/1970 00:00:00", Now())
Comment

PREVIOUS NEXT
Code Example
Python :: how to make a random number generator in python 
Python :: get maximum value index after groupby 
Python :: how to check if how much time is your code taking to run in python 
Python :: two underscores python 
Python :: insert into string python 
Python :: urllib_errors 
Python :: remove dict last element 
Python :: inheritance in python 3 example 
Python :: how to perform group by with django orm 
Python :: literal_eval in python 
Python :: destory image in pygame 
Python :: Iterating With for Loops in Python 
Python :: how to create a User and User profile in django rest framework 
Python :: amazon redshift 
Python :: python typing 
Python :: import user model 
Python :: dm command in discord.py 
Python :: joining lists python 
Python :: python match case 
Python :: python - convert a list column into miltiple columns 
Python :: how to download a pip package with python and os 
Python :: python delete key if exists 
Python :: Encrypting a message in Python 
Python :: python print bytes 
Python :: django reverse vs reverse_lazy 
Python :: textrank python implementation 
Python :: how to loop through an array in python 
Python :: sum up list python 
Python :: how to store the variable in dictionary 
Python :: python script to write dataframe on excel 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =