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

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”); 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”); which uses the standard “round-trip” style (ISO 8601) to give you … Read more

How can I parse / create a date time stamp formatted with fractional seconds UTC timezone (ISO 8601, RFC 3339) in Swift?

Swift 4 • iOS 11.2.1 or later extension ISO8601DateFormatter { convenience init(_ formatOptions: Options) { self.init() self.formatOptions = formatOptions } } extension Formatter { static let iso8601withFractionalSeconds = ISO8601DateFormatter([.withInternetDateTime, .withFractionalSeconds]) } extension Date { var iso8601withFractionalSeconds: String { return Formatter.iso8601withFractionalSeconds.string(from: self) } } extension String { var iso8601withFractionalSeconds: Date? { return Formatter.iso8601withFractionalSeconds.date(from: self) } } … 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