How to convert Python’s .isoformat() string back into datetime object [duplicate]

Python 3.7+ As of Python 3.7 there is a method datetime.fromisoformat() which is exactly the reverse for isoformat(). Older Python If you have older Python, then this is the current best “solution” to this question: pip install python-dateutil Then… import datetime import dateutil def getDateTimeFromISO8601String(s): d = dateutil.parser.parse(s) return d

How do I get an ISO 8601 date on iOS?

Use NSDateFormatter: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@”en_US_POSIX”]; [dateFormatter setLocale:enUSPOSIXLocale]; [dateFormatter setDateFormat:@”yyyy-MM-dd’T’HH:mm:ssZZZZZ”]; [dateFormatter setCalendar:[NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]]; NSDate *now = [NSDate date]; NSString *iso8601String = [dateFormatter stringFromDate:now]; And in Swift: let dateFormatter = DateFormatter() let enUSPosixLocale = Locale(identifier: “en_US_POSIX”) dateFormatter.locale = enUSPosixLocale dateFormatter.dateFormat = “yyyy-MM-dd’T’HH:mm:ssZZZZZ” dateFormatter.calendar = Calendar(identifier: .gregorian) let iso8601String = … Read more

Illegal pattern character ‘T’ when parsing a date string to java.util.Date

Update for Java 8 and higher You can now simply do Instant.parse(“2015-04-28T14:23:38.521Z”) and get the correct thing now, especially since you should be using Instant instead of the broken java.util.Date with the most recent versions of Java. You should be using DateTimeFormatter instead of SimpleDateFormatter as well. Original Answer: The explanation below is still valid … Read more

Python UTC datetime object’s ISO format doesn’t include Z (Zulu or Zero offset)

Option: isoformat() Python’s datetime does not support the military timezone suffixes like ‘Z’ suffix for UTC. The following simple string replacement does the trick: In [1]: import datetime In [2]: d = datetime.datetime(2014, 12, 10, 12, 0, 0) In [3]: str(d).replace(‘+00:00’, ‘Z’) Out[3]: ‘2014-12-10 12:00:00Z’ str(d) is essentially the same as d.isoformat(sep=’ ‘) See: Datetime, … 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

How do I format a date as ISO 8601 in moment.js?

moment().toISOString(); // or format() – see below http://momentjs.com/docs/#/displaying/as-iso-string/ Update Based on the answer: by @sennet and the comment by @dvlsg (see Fiddle) it should be noted that there is a difference between format and toISOString. Both are correct but the underlying process differs. toISOString converts to a Date object, sets to UTC then uses the … Read more

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