python-dateutil


datetime strftime does not output correct timestamp

六月ゝ 毕业季﹏ 提交于 2020-01-14 14:56:29
问题 The following: >>> from dateutil.parser import parse >>> parse("2013-07-02 00:00:00 -0000") datetime.datetime(2013, 7, 2, 0, 0, tzinfo=tzutc()) shows that the time should be 12am on July 2nd 2013 in UTC. However: >>> parse("2013-07-02 00:00:00 -0000").strftime("%s") '1372744800' 1372744800 is actually Tue, 02 Jul 2013 06:00:00 UTC, which is wrong. Very confused. 回答1: See this question: Convert python datetime to epoch with strftime Python doesn't actually support %s as an argument to strftime

Extraction of some date formats failed when using Dateutil in Python

蹲街弑〆低调 提交于 2020-01-14 03:08:10
问题 I have gone through multiple links before posting this question so please read through and below are the two answers which have solved 90% of my problem: parse multiple dates using dateutil How to parse multiple dates from a block of text in Python (or another language) Problem : I need to parse multiple dates in multiple formats in Python Solution by Above Links : I am able to do so but there are still certain formats which I am not able to do so. Formats which still can't be parsed are:

Extraction of some date formats failed when using Dateutil in Python

孤街醉人 提交于 2020-01-14 03:08:06
问题 I have gone through multiple links before posting this question so please read through and below are the two answers which have solved 90% of my problem: parse multiple dates using dateutil How to parse multiple dates from a block of text in Python (or another language) Problem : I need to parse multiple dates in multiple formats in Python Solution by Above Links : I am able to do so but there are still certain formats which I am not able to do so. Formats which still can't be parsed are:

Python dateutil.parser.parse parses month first, not day

故事扮演 提交于 2020-01-09 19:45:50
问题 I'm using dateutil.parser.parse to format a date from a string. But now it mixes up the month and the day. I have a string that contains 05.01.2015 . After dateutil.parser.parse("05.01.2015") it returns: datetime.datetime(2015, 5, 1, 0, 0) I hoped the it would return (2015, 1, 5, 0, 0) How can I tell the code that the format is dd.mm.yyyy ? For the record, 25.01.2015 will be parsed as (2015, 1, 25, 0, 0) , as expected. 回答1: Specify dayfirst=True : >>> dateutil.parser.parse("05.01.2015",

Using datetime.timedelta to add years

杀马特。学长 韩版系。学妹 提交于 2020-01-03 19:43:07
问题 I am doing some time calculations in Python. Goal: Part of this is trying to : Given a date, add time interval (X years, X months, X weeks), return date ie input args: input_time (datetime.date), interval (datetime.timedelta) return: datetime.date I looked at the datetime and datetime.timedelta docs class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)¶. These seem to work well if I want to add a certain number of hours or weeks. However,

dateutil.parser.parse() gives error “initial_value must be unicode or None, not str” on Windows platform

旧巷老猫 提交于 2020-01-02 03:47:06
问题 I'm sure there's a really simple solution to this, but I'm still fairly new to Python. I'm trying to use dateutil.parser.parse() to parse a string with a timestamp in it: >>> import dateutil.parser >>> a = dateutil.parser.parse("2011-10-01 12:00:00+01:00") >>> print a 2011-10-01 12:00:00+01:00 This works fine on my Linux server, but on my Windows test box it gives an error: >>> import dateutil.parser >>> a = dateutil.parser.parse("2011-10-01 12:00:00+01:00") Traceback (most recent call last):

Inferring date format versus passing a parser

荒凉一梦 提交于 2020-01-02 00:55:24
问题 Pandas internals question: I've been surprised to find a few times that explicitly passing a callable to date_parser within pandas.read_csv results in much slower read time than simply using infer_datetime_format=True . Why is this? Will timing differences between these two options be date-format-specific, or what other factors will influence their relative timing? In the below case, infer_datetime_format=True takes one-tenth the time of passing a date parser with a specified format. I would

dateutil.parser.parse() and lost timezone information

烂漫一生 提交于 2020-01-01 09:40:13
问题 I am trying to dateutil.parser.parse() to parse the default str(datetime.datetime.now()) output using timezone-aware datetimes. However, parse() seems to lose the timezone information and replace it with the local time timezone. Below is the IPython output: In [1]: from django.utils.timezone import now In [3]: import dateutil In [4]: t = now() In [6]: print t 2014-07-14 08:51:49.123342+00:00 In [7]: st = unicode(t) In [8]: print dateutil.parser.parse(st) 2014-07-14 08:51:49.123342+02:00 As

Python - Getting the date format [duplicate]

半世苍凉 提交于 2019-12-30 10:57:10
问题 This question already has answers here : How to determine appropriate strftime format from a date string? (3 answers) Closed 2 years ago . I'm getting a date as a string, then I'm parsing it to datetime object. Is there any way to check what's is the date format of the object? Let's say that this is the object that I'm creating: modified_date = parser.parse("2015-09-01T12:34:15.601+03:00") How can i print or get the exact date format of this object, i need this in order to verify that it's in

From a timezone and a UTC time, get the difference in seconds vs local time at that point in time

試著忘記壹切 提交于 2019-12-29 01:26:06
问题 This should be very simple, but I can't quite figure it out in Python. I want to have a function which takes two arguments, a UTC time in seconds and a zoneinfo name like 'Europe/Vienna' and returns the offset in seconds from local time and UTC for that point in time. In C it would be: /* ... code to to set local time to the time zone I want to compare against, not shown here. Then call function below to get difference vs localtime. Hardly an ideal solution, but just to demonstrate what I

工具导航Map