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

Java 8 Date and Time: parse ISO 8601 string without colon in offset [duplicate]

If you want to parse all valid formats of offsets (Z, ±hh:mm, ±hhmm and ±hh), one alternative is to use a java.time.format.DateTimeFormatterBuilder with optional patterns (unfortunatelly, it seems that there’s no single pattern letter to match them all): DateTimeFormatter formatter = new DateTimeFormatterBuilder() // date/time .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME) // offset (hh:mm – “+00:00” when it’s zero) .optionalStart().appendOffset(“+HH:MM”, … Read more

Parsing ISO 8601 date format like 2015-06-27T13:16:37.363Z in Java [duplicate]

Try with this pattern (note the X at the end and the ‘T’ in the middle): “yyyy-MM-dd’T’HH:mm:ss.SSSX” From Java’s SimpleDateFormat’s documentation: ISO 8601 Time zone: … For parsing, “Z” is parsed as the UTC time zone designator. And, from the part where it describes the different characters: X – Time zone – ISO 8601 time … Read more

Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate?

I have a similiar but slightly more complex problem, and I’ve found a very simple solution! The problem: My incoming ISO8601 dates look like this: 2006-06-14T11:06:00+02:00 They have a timezone offset at the end. The solution: Use Peter Hosey’s ISO8601DateFormatter which you can download from here. ISO8601DateFormatter *formatter = [[ISO8601DateFormatter alloc] init]; NSDate *theDate = … Read more

Cannot parse String in ISO 8601 format, lacking colon in offset, to Java 8 Date

tl;dr Until bug is fixed: OffsetDateTime.parse( “2018-02-13T10:20:12.120+0000” , DateTimeFormatter.ofPattern( “uuuu-MM-dd’T’HH:mm:ss.SSSX” ) ) When bug is fixed: OffsetDateTime.parse( “2018-02-13T10:20:12.120+0000” ) Details You are using the wrong classes. Avoid the troublesome old legacy classes such as Date, Calendar, and SimpleDateFormat. Now supplanted by the java.time classes. The ZonedDateTime class you used is good, it is part of … 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