Has anyone converted this kind of times before?
2020-10-12T01:00:00-07:00 to 2020-10-12T09:00:00-07:00
equals
Monday, October 12, 2020 at 10:00 AM – 6:00 PM UTC+02
to datetime objects?
2020-10-12T01:00:00-07:00
<--date--> <-time-><zone>
This means 1am on October 12th, 2020, in the time zone 7 hours west of UTC (running through the middle of the US, basically).
It's actually one of the ISO8601 formats, used for date/time data interchange.
I believe the dateutil.parser() library can handle this in Python.
Related
It is 2022/06/28 actually 28th of June 2022; I noticed when I try to get the current time from Python console two different results are possible the Eastern Time (Toronto, Montreal and New York). So what is the difference between these two parameters? I am going to answer the question:
"EST" is not accurate if you want to get the current time in New York because it represents Eastern Standard Time (UTC-05:00), which is one hour behind Eastern Daylight Time (UTC-04:00). Due to daylight savings, New York will observe either EST or EDT depending on the time of year.
"US/Eastern" is preferable to "EST" as it represents the Eastern Time Zone in the United States and will account for any shifts due to daylight savings. However, the zone representing "US/Eastern" has been renamed to "America/New_York", and is maintained for backwards compatibility.
The first way to get the current time in Toronto is:
from datetime import datetime
from pytz import timezone
tz = timezone('EST')
print(datetime.now(tz))
The output is the following:
2022-06-28 16:23:23.333585-05:00
The second way to get the current time in Toronto is:
from datetime import datetime
from pytz import timezone
tz = timezone('US/Eastern')
print(datetime.now(tz))
The output is the following:
2022-06-28 17:24:42.944669-04:00
Conclusion:
If you use "EST" it is sometimes 1 hour ahead of the true time. I recommend you usually use 'US/Eastern'.
I'm trying to convert a string to DateTime object, The string:
Saturday 8th of August 2020 07:48:11 AM CDT
I'm using arrow package
arrow.get('Saturday 8th of August 2020 09:23:34 AM CDT', 'dddd Mt[h] of MMMM YYYY HH:mm:ss A ZZZ')
I'm getting the following error
arrow.parser.ParserError: Could not parse timezone expression "CDT"
I couldn't find any way to convert the CDN part into timezone.
Has said in the documentation, some abbreviations are ambiguous. You can use for example America/Chicago instead of CDT
I need to parse RSS feed. I am using feedparser on python. Basically my task is to run script every N seconds and check for last feed. I come up with idea to check is date is younger than 15 seconds each iteration. But there is a problem pubDate has different timezone.
'Published_parsed' I think working not correct because it gives me these:
2020-06-17 05:46:45
-
Wed, 17 Jun 2020 04:46:45 GMT
and this
2020-06-17 11:19:39
-
Wed, 17 Jun 2020 10:19:39 IST
Thus it's not parsed to one timezone. I tried to check it to each timezone using pytz, but there is no IST timezone, what is not good to me.
How can I parse this varioty of dates to one timezone time.
Wed, 17 Jun 2020 13:12:43 IST
Tue, 16 Jun 2020 21:49:32 GMT
I'm working in Python with a number of libraries at play.
I have a group of files on a Linux server that have the last modified timestamp of midnight on January 1, 1980 (unix timestamp 315532800.0). The last changed timestamp however is recent. What could have caused this?
In particular, Jan 1 1980 is a suspiciously round number, but not one of the usual suspicious round numbers.
The culprit is the Python zipfile library. If you don't pass a second parameter to ZipInfo, it defaults to Jan 1, 1980: https://docs.python.org/3/library/zipfile.html#zipfile.ZipInfo
The problem. In my Django application, users create tasks for scheduled execution. The users are quite non-technical, and it would be great if they can write conventional human-readable expressions to define when to execute certain task, such as:
every monday
every fri, wed
daily
1, 14, 20 of each month
every fri; every end of month
This is inspired by Todoist. For now, only dates are necessary; no times. I've spent a couple of hours googling for a library to do that, but with no luck. I am expecting a function, say, in_range(expression, date), such that:
>>> in_range('every monday, wednesday', date(2014, 4, 28))
True
>>> in_range('every end of month', date(2014, 5, 12))
False
>>> in_range('every millenium', date(2014, 5, 8))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: unknown token "millenium".
Variants. That's what I've looked through.
Standard datetime library does date parsing, but not date range parsing as per above.
Python-dateutil - supports recurring dates via rrule, very functional, but still does not support parsing.
Python-crontab and Python-croniter accept standard Unix crontab syntax (and allow to specify weekdays, etc), but still such syntax is a way too technical and I'd like to avoid it if possible.
Arrow and Parsedatetime do not support the feature.
So, is there a Python code snippet, or a library that I missed, to do the thing? If not, I'm going to write the parser myself. Would like to release it in open source if it appears to be not too bad.
Recurrent is a library that will do natural language date parsing with support for recurring dates. It doesn't match the API you provided, but allows you to create rules that can be used with Python's datetime library.
From their Github page:
Natural language parsing of dates and recurring events
Examples
Date times
next tuesday
tomorrow
in an hour
Recurring events
on weekdays
every fourth of the month from jan 1 2010 to dec 25th 2020
each thurs until next month
once a year on the fourth thursday in november
tuesdays and thursdays at 3:15
Messy strings
Please schedule the meeting for every other tuesday at noon
Set an alarm for next tuesday at 11pm