How do I output an ISO 8601 formatted string in JavaScript?

There is already a function called toISOString(): var date = new Date(); date.toISOString(); //”2011-12-19T15:28:46.493Z” If, somehow, you’re on a browser that doesn’t support it, I’ve got you covered: if (!Date.prototype.toISOString) { (function() { function pad(number) { var r = String(number); if (r.length === 1) { r=”0″ + r; } return r; } Date.prototype.toISOString = function() … Read more

How do I translate an ISO 8601 datetime string into a Python datetime object? [duplicate]

I prefer using the dateutil library for timezone handling and generally solid date parsing. If you were to get an ISO 8601 string like: 2010-05-08T23:41:54.000Z you’d have a fun time parsing that with strptime, especially if you didn’t know up front whether or not the timezone was included. pyiso8601 has a couple of issues (check … Read more

ISO time (ISO 8601) in Python

Local to ISO 8601: import datetime datetime.datetime.now().isoformat() >>> 2020-03-20T14:28:23.382748 UTC to ISO 8601: import datetime datetime.datetime.utcnow().isoformat() >>> 2020-03-20T01:30:08.180856 Local to ISO 8601 without microsecond: import datetime datetime.datetime.now().replace(microsecond=0).isoformat() >>> 2020-03-20T14:30:43 UTC to ISO 8601 with TimeZone information (Python 3): import datetime datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat() >>> 2020-03-20T01:31:12.467113+00:00 UTC to ISO 8601 with Local TimeZone information without microsecond (Python 3): import datetime datetime.datetime.now().astimezone().replace(microsecond=0).isoformat() >>> 2020-03-20T14:31:43+13:00 Local to … Read more

Converting ISO 8601-compliant String to java.util.Date

Unfortunately, the time zone formats available to SimpleDateFormat (Java 6 and earlier) are not ISO 8601 compliant. SimpleDateFormat understands time zone strings like “GMT+01:00” or “+0100”, the latter according to RFC # 822. Even if Java 7 added support for time zone descriptors according to ISO 8601, SimpleDateFormat is still not able to properly parse … Read more

How do I parse an ISO 8601-formatted date?

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

Given a DateTime object, how do I get an ISO 8601 date in string format?

Note to readers: Several commenters have pointed out some problems in this answer (related particularly to the first suggestion). Refer to the comments section for more information. DateTime.UtcNow.ToString(“yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz”, CultureInfo.InvariantCulture); Using custom date-time formatting, this gives you a date similar to 2008-09-22T13:57:31.2311892-04:00. Another way is: DateTime.UtcNow.ToString(“o”, CultureInfo.InvariantCulture); which uses the standard “round-trip” style (ISO 8601) to … Read more

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