Why can’t OffsetDateTime parse ‘2016-08-24T18:38:05.507+0000’ in Java 8

You are calling the following method. public static OffsetDateTime parse(CharSequence text) { return parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME); } It uses uses DateTimeFormatter.ISO_OFFSET_DATE_TIME as DateTimeFormatter which, as stated in the javadoc, does the following: The ISO date-time formatter that formats or parses a date-time with an offset, such as ‘2011-12-03T10:15:30+01:00’. If you want to parse a date with … Read more

DateTimeParse Exception

The devil is in the detail. You are basically doing it correctly, except: You need to provide a locale for the formatter. By parsing into a LocalDateTime you are losing information and possibly getting an unexpected result. So I suggest: DateTimeFormatter formatter = DateTimeFormatter.ofPattern( “EEE MMM dd HH:mm:ss zzz yyyy”, Locale.ROOT); String linesplit8 = “Wed … Read more

Convert date into AEST using java

You have to use the formatter when parsing the date string. Also you need to tell it to change the zone or zone offset to get it into AEST/AEDT. This might work: DateTimeFormatter dtf = DateTimeFormatter.ofPattern(“yyyy-MM-dd’T’HH:mm:ss.SSSXX”); ZonedDateTime zdt = OffsetDateTime.parse(input, dtf) .atZoneSameInstant(ZoneId.of(“Australia/Sydney”)); String dateInTimeZone = zdt.format(dtf); The offset will appear as “+1000” or “+1100” depending … Read more

Java: Date parsing, why do I get an error

Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss.SSSZ”);//2018-02-05T18:00:51.001+0000 String text = dateFormat.format(date); try { Date test = dateFormat.parse(text); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } worked for me. With “SSSZ” instead of “SZ” at the end of the pattern.

How to parse a date string into a c++11 std::chrono time_point or similar?

std::tm tm = {}; std::stringstream ss(“Jan 9 2014 12:35:34”); ss >> std::get_time(&tm, “%b %d %Y %H:%M:%S”); auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm)); GCC prior to version 5 doesn’t implement std::get_time. You should also be able to write: std::tm tm = {}; strptime(“Thu Jan 9 2014 12:35:34”, “%a %b %d %Y %H:%M:%S”, &tm); auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm));

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