How do I parse an ISO 8601-formatted date and time?

isoparse function from python-dateutil The python-dateutil package has dateutil.parser.isoparse to 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.parser … Read more

Converting ISO 8601 date time to seconds in Python

If you want to get the seconds since epoch, you can use python-dateutil to convert it to a datetime object and then convert it so seconds using the strftime method. Like so: >>> import dateutil.parser as dp >>> t=”1984-06-02T19:05:00.000Z” >>> parsed_t = dp.parse(t) >>> t_in_seconds = parsed_t.timestamp() >>> t_in_seconds ‘455051100’ So you were halfway there … Read more

Convert an RFC 3339 time to a standard Python timestamp

You don’t include an example, but if you don’t have a Z-offset or timezone, and assuming you don’t want durations but just the basic time, then maybe this will suit you: import datetime as dt >>> dt.datetime.strptime(‘1985-04-12T23:20:50.52’, ‘%Y-%m-%dT%H:%M:%S.%f’) datetime.datetime(1985, 4, 12, 23, 20, 50, 520000) The strptime() function was added to the datetime module in … Read more

How do I parse RFC 3339 datetimes with Java?

tl;dr Instant.parse( “2011-05-03T11:58:01Z” ) ISO 8601 Actually, RFC 3339 is but a mere self-proclaimed “profile” of the actual standard, ISO 8601. The RFC is different in that it purposely violates ISO 8601 to allow a negative offset of zero hours (-00:00) and gives that a semantic meaning of “offset unknown“. That semantic seems like a … Read more

ISO to datetime object: ‘z’ is a bad directive [duplicate]

Welcome to Python datetime! Dealing with dates and times is necessarily complex, and Python doesn’t come fully with batteries included in this case. You can’t use %z in strptime because Python has no classes to represent timezones (you are supposed to implement your own, or better yet include some other libraries). You want to use … Read more

Output RFC 3339 Timestamp in Java

Starting in Java 7, there’s the X pattern string for ISO8601 time zone. For strings in the format you describe, use XXX. See the documentation. Sample: System.out.println(new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ssXXX”) .format(new Date())); Result: 2014-03-31T14:11:29+02:00

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

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, XmlDateTimeSerializationMode dateTimeOption) to convert a (UTC) datetime to a string. Ref. http://msdn.microsoft.com/en-us/library/ms162342(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/ms162344(v=vs.110).aspx

Convert timestamps with offset to datetime obj using strptime

The Python 2 strptime() function indeed does not support the %z format for timezones (because the underlying time.strptime() function doesn’t support it). You have two options: Ignore the timezone when parsing with strptime: time_obj = datetime.datetime.strptime(time_str[:19], ‘%Y-%m-%dT%H:%M:%S’) use the dateutil module, it’s parse function does deal with timezones: from dateutil.parser import parse time_obj = parse(time_str) … Read more

Generate RFC 3339 timestamp in Python [duplicate]

UPDATE 2021 In Python 3.2 timezone was added to the datetime module allowing you to easily assign a timezone to UTC. >>> import datetime >>> n = datetime.datetime.now(datetime.timezone.utc) >>> n.isoformat() ‘2021-07-13T15:28:51.818095+00:00’ previous answer: Timezones are a pain, which is probably why they chose not to include them in the datetime library. try pytz, it has … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)