utc

Convert String "YYYY-MM-DD hh:mm:ss Etc/GMT" to timestamp in UTC pandas

Convert String "YYYY-MM-DD hh:mm:ss Etc/GMT" to timestamp in UTC pandas Question: I have a pandas column of datetime-like string values like this exampe: exammple_value = "2022-06-24 16:57:33 Etc/GMT" Expected output Timestamp(‘2022-06-24 16:57:33+0000′, tz=’UTC’) Etc/GMT is the timezone, you can get it in python with: import pytz list(filter(lambda x: ‘GMT’ in x, pytz.all_timezones))[0] —- OUT: ‘Etc/GMT’ …

Total answers: 1

how to convert list of dates into UTC dates(timestamp)

how to convert list of dates into Unix timestamps Question: I have a list of dates that has unordered length and with day,mon,year pattern.and i want to return both ordered date and date with utc format. what i have tried: from datetime import timezone import datetime data_lst = [’07 17′, ’01 2017′, ’05 2015′, ‘2016’, …

Total answers: 1

convert time to UTC in pandas

convert time to UTC in pandas Question: I have multiple csv files, I’ve set DateTime as the index. df6.set_index("gmtime", inplace=True) #correct the underscores in old datetime format df6.index = [" ".join( str(val).split("_")) for val in df6.index] df6.index = pd.to_datetime(df6.index) The time was put in GMT, but I think it’s been saved as BST (British summertime) …

Total answers: 2

Convert datetime.datetime from UTC to CEST one hour to less

Convert datetime.datetime from UTC to CEST one hour to less Question: If I run the following code I convert the datetime.datetime from utc to cest, but it does not work right. Correct would be if it would change from 21:29 to 23:29 because the time difference is 2 hours from_zone = tz.gettz(‘UTC’) to_zone = tz.gettz(‘CEST’) …

Total answers: 1

Python Datetime : use strftime() with a timezone-aware date

Python Datetime : use strftime() with a timezone-aware date Question: Suppose I have date d like this : >>> d datetime(2009, 4, 19, 21, 12, tzinfo=tzoffset(None, -7200)) As you can see, it is “timezone aware”, there is an offset of 2 Hour, utctime is >>> d.utctimetuple() time.struct_time(tm_year=2009, tm_mon=4, tm_mday=19, tm_hour=23, tm_min=12, tm_sec=0, tm_wday=6, tm_yday=109, tm_isdst=0) …

Total answers: 4

flask: convert utc time to user's local time

flask: convert utc time to user's local time Question: I’m trying to convert a UTC time to the appropriate local time in a flask application. I’m wondering if I can detect the user’s timezone and dynamically set it. This is my code so far which works for everyone in the US/Pacific timezone only (datetimefilter pulled …

Total answers: 2

How to set the timezone in Django?

How to set the timezone in Django? Question: In my django project’s settings.py file, I have this line : TIME_ZONE = ‘UTC’ But I want my app to run in UTC+2 timezone, so I changed it to TIME_ZONE = ‘UTC+2’ It gives the error ValueError: Incorrect timezone setting: UTC+2. What is the correct way of …

Total answers: 13

pytz – Converting UTC and timezone to local time

pytz – Converting UTC and timezone to local time Question: I have a datetime in utc time zone, for example: utc_time = datetime.datetime.utcnow() And a pytz timezone object: tz = timezone(‘America/St_Johns’) What is the proper way to convert utc_time to the given timezone? Asked By: Tzach || Source Answers: May I recommend to use arrow? …

Total answers: 6

How to get an UTC date string in Python?

How to get an UTC date string in Python? Question: I am trying to get utc date string as “YYYYMMDD” For now I do the following, nowTime = time.gmtime(); nowDate = date(nowTime.tm_year, nowTime.tm_mon, nowTime.tm_mday) print nowDate.strftime(‘%Y%m%d’) I used to do: datetime.date.today().strftime() but this gives me date string in local TZ How can I get an …

Total answers: 1

Convert python datetime to epoch with strftime

Convert python datetime to epoch with strftime Question: I have a time in UTC from which I want the number of seconds since epoch. I am using strftime to convert it to the number of seconds. Taking 1st April 2012 as an example. >>>datetime.datetime(2012,04,01,0,0).strftime(‘%s’) ‘1333234800’ 1st of April 2012 UTC from epoch is 1333238400 but …

Total answers: 8