rfc3339

Parse rfc3339 date strings in Python? [duplicate]

风格不统一 提交于 2019-11-27 00:20:51
问题 This question already has answers here : How do I parse an ISO 8601-formatted date? (26 answers) Closed 4 years ago . I have a datasets where all the dates have the following format: 2012-10-09T19:00:55Z I'd like to be able to be able to use methods like .weekday on them. How do I convert them to the proper format in Python? 回答1: You can use dateutil.parser.parse to parse strings into datetime objects. dateutil.parser.parse will attempt to guess the format of your string, if you know the

How do I parse and convert a DateTime to the RFC 3339 date-time format?

眉间皱痕 提交于 2019-11-26 22:22:10
问题 How do I convert a DateTime structure to its equivalent RFC 3339 formatted string representation and/or parse this string representation back to a DateTime structure? The RFC-3339 date-time format is used in a number of specifications such as the Atom Syndication Format. 回答1: You don't need to write your own conversion code. Just use XmlConvert.ToDateTime(string s, XmlDateTimeSerializationMode dateTimeOption) to parse a RFC-3339 string, and XmlConvert.ToString(DateTime value,

Convert an RFC 3339 time to a standard Python timestamp

杀马特。学长 韩版系。学妹 提交于 2019-11-26 20:24:47
问题 Is there an easy way to convert an RFC 3339 time into a regular Python timestamp? I've got a script which is reading an ATOM feed and I'd like to be able to compare the timestamp of an item in the ATOM feed to the modification time of a file. I notice from the ATOM spec, that ATOM dates include a time zone offset ( Z<a number> ) but, in my case, there's nothing after the Z so I guess we can assume GMT. I suppose I could parse the time with a regex of some sort but I was hoping Python had a

ISO to datetime object: &#39;z&#39; is a bad directive [duplicate]

流过昼夜 提交于 2019-11-26 15:26:45
This question already has an answer here: Convert timestamps with offset to datetime obj using strptime 4 answers Converting string with UTC offset to a datetime object [duplicate] 1 answer I am trying to convert ISO to datetime using the code below: dt = datetime.datetime.strptime("2013-07-23T15:10:59.342107+01:00", "%Y-%m-%dT%H:%M:%S.%f%z") and I'm getting the error below: 'z' is a bad directive in format '%Y-%m-%dT%H:%M:%S.%f%z' What is the best way to convert an ISO string of above the format to a datetime object? I'm using Python version 2.7.6. Max Welcome to Python datetime! Dealing with

Generate RFC 3339 timestamp in Python

白昼怎懂夜的黑 提交于 2019-11-26 09:35:06
问题 I\'m trying to generate an RFC 3339 UTC timestamp in Python. So far I\'ve been able to do the following: >>> d = datetime.datetime.now() >>> print d.isoformat(\'T\') 2011-12-18T20:46:00.392227 My problem is with setting the UTC offset. According to the docs, the classmethod datetime.now([tz]) , takes an optional tz argument where tz must be an instance of a class tzinfo subclass , and datetime.tzinfo is an abstract base class for time zone information objects. This is where I get lost- How

ISO to datetime object: &#39;z&#39; is a bad directive [duplicate]

我们两清 提交于 2019-11-26 05:58:46
问题 This question already has an answer here: Convert timestamps with offset to datetime obj using strptime 4 answers Converting string with UTC offset to a datetime object [duplicate] 1 answer I am trying to convert ISO to datetime using the code below: dt = datetime.datetime.strptime(\"2013-07-23T15:10:59.342107+01:00\", \"%Y-%m-%dT%H:%M:%S.%f%z\") and I\'m getting the error below: \'z\' is a bad directive in format \'%Y-%m-%dT%H:%M:%S.%f%z\' What is the best way to convert an ISO string of

How to convert a timezone aware string to datetime in python without dateutil?

心不动则不痛 提交于 2019-11-26 03:57:19
问题 I have to convert a timezone-aware string to python datetime object. For example 2012-11-01T04:16:13-04:00 . I find there\'s a dateutil module which have a parse function to do it, but I don\'t really want to use it as it adds a dependency. So how can I do it? I have tried something like the following, but with no luck. datetime.datetime.strptime(\"2012-11-01T04:16:13-04:00\", \"%Y-%m-%dT%H:%M:%S%Z\") 回答1: As of Python 3.7, datetime.datetime.fromisoformat() can handle your format: >>> import

Convert timestamps with offset to datetime obj using strptime

孤街醉人 提交于 2019-11-25 22:36:13
问题 I am trying to convert time-stamps of the format \"2012-07-24T23:14:29-07:00\" to datetime objects in python using strptime method. The problem is with the time offset at the end(-07:00). Without the offset i can successfully do time_str = \"2012-07-24T23:14:29\" time_obj=datetime.datetime.strptime(time_str,\'%Y-%m-%dT%H:%M:%S\') But with the offset i tried time_str = \"2012-07-24T23:14:29-07:00\" time_obj=datetime.datetime.strptime(time_str,\'%Y-%m-%dT%H:%M:%S-%z\'). But it gives a Value

How do I parse an ISO 8601-formatted date?

半世苍凉 提交于 2019-11-25 22:18:11
问题 I need to parse RFC 3339 strings like \"2008-09-03T20:56:35.450686Z\" into Python\'s datetime type. I have found strptime in the Python standard library, but it is not very convenient. What is the best way to do this? 回答1: The python-dateutil package can parse not only RFC 3339 datetime strings like the one in the question, but also other ISO 8601 date and time strings that don't comply with RFC 3339 (such as ones with no UTC offset, or ones that represent only a date). >>> import dateutil

How to create a date time stamp and format as ISO 8601, RFC 3339, UTC time zone?

无人久伴 提交于 2019-11-25 22:07:23
问题 How to generate a date time stamp, using the format standards for ISO 8601 and RFC 3339? The goal is a string that looks like this: \"2015-01-01T00:00:00.000Z\" Format: year, month, day, as \"XXXX-XX-XX\" the letter \"T\" as a separator hour, minute, seconds, milliseconds, as \"XX:XX:XX.XXX\". the letter \"Z\" as a zone designator for zero offset, a.k.a. UTC, GMT, Zulu time. Best case: Swift source code that is simple, short, and straightforward. No need to use any additional framework,