Questions tagged [datetime-parsing]

423 questions
9
votes
4 answers

DateTimeFormatter Accepting Multiple Dates and Converting to One (java.time library)

I am trying to write a DateTimeFormatter that will allow me to take in multiple different String formats, and then convert the String formats to a specific type. Due to the scope of the project and the code that already exists, I cannot use a…
AlexK
  • 336
  • 8
  • 21
  • 41
8
votes
2 answers

Java 8 Parse ISO-8601 date ignoring presence (or absence) of timezone

My application should be able to parse date ignoring timezone (I always know for sure that it is UTC). The problem is that the date might come in both following forms - 2017-09-11T12:44:07.793Z 0001-01-01T00:00:00 I can parse the first one using…
silent-box
  • 1,649
  • 3
  • 21
  • 40
8
votes
3 answers

Why does Java 8 DateTimeFormatter allows an incorrect month value in ResolverStyle.STRICT mode?

Why does this test pass, while the month value is obviously invalid (13)? @Test public void test() { String format = "uuuuMM"; String value = "201713"; DateTimeFormatter.ofPattern(format).withResolverStyle(ResolverStyle.STRICT) …
Virginie
  • 909
  • 3
  • 12
  • 32
8
votes
1 answer

Jackson - Can't deserialize datetime with timezone offset 'unparsed text found at index 23'

My datetime has to come from frontend with timezone offset: 2017-07-04T06:00:00.000+01:00 I cannot deserialize it with Jackson. The error is: Text '2017-07-04T06:00:00.000+01:00' could not be parsed, unparsed text found at index 23; I was trying…
Marek Urbanowicz
  • 12,659
  • 16
  • 62
  • 87
8
votes
4 answers

how to get a formatted date as milliseconds?

I have a formatted date from sqllite database, to use this in a graph view I need to format it in a long number. The format is: 2012-07-11 10:55:21 how can I convert it to milliseconds?
Reyjohn
  • 2,654
  • 9
  • 37
  • 63
8
votes
1 answer

parsing date string in python (convert string to date)

I have a datetime string in the form of a string as: 2011-10-23T08:00:00-07:00 How do i parse this string as the datetime object. I did the following reading the documentation: date = datetime.strptime(data[4],"%Y-%m-%d%Z") BUt I get the error …
frazman
  • 32,081
  • 75
  • 184
  • 269
8
votes
1 answer

Correctly parse date string with timezone information

I'm receiving a formatted date string like this via the pivotal tracker API: "2012/06/05 17:42:29 CEST" I want to convert this string to a UTC datetime object, it looks like python-dateutil does not recognize that timezone, pytz doesn't know it…
Strayer
  • 3,050
  • 3
  • 30
  • 40
7
votes
2 answers

Date string to epoch seconds (UTC)

Question I want to parse a date-time given as string (UTC) into seconds since epoch. Example (see EpochConverter): 2019-01-15 10:00:00 -> 1547546400 Problem The straightforward solution, which is also accepted in a very related question C++…
Zabuzard
  • 25,064
  • 8
  • 58
  • 82
7
votes
7 answers

How to convert UTC Date String and remove the T and Z in Java?

Am using Java 1.7. Trying to convert: 2018-05-23T23:18:31.000Z into 2018-05-23 23:18:31 DateUtils class: public class DateUtils { public static String convertToNewFormat(String dateStr) throws ParseException { TimeZone utc =…
PacificNW_Lover
  • 4,746
  • 31
  • 90
  • 144
7
votes
3 answers

java.time DateTimeFormatter parsing with flexible fallback values

I am trying to port some code from joda time to java time. JodaTime had the possibility to specify a fallback value for the year like this parser.withDefaultYear((new DateTime(DateTimeZone.UTC)).getYear()).parseDateTime(text); Regardless how the…
alr
  • 1,744
  • 1
  • 10
  • 11
7
votes
3 answers

What system default date format to use?

I'm setting the standards for our application. I've been wondering, what default date format should I choose to use ? It should be: Internationalization & timezone aware, the format should be able to represent user local time Can be efficiently…
Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151
7
votes
1 answer

java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME fails to parse time zone names

I'm trying to parse timestamps from a data source that is defined as using RFC1123-compatible date time specifications. My code is: value = Instant.from (DateTimeFormatter.RFC_1123_DATE_TIME.parse (textValue)); This works fine for some data, but I…
Jules
  • 14,841
  • 9
  • 83
  • 130
7
votes
5 answers

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

The expression OffsetDateTime.parse("2016-08-24T18:38:05.507+0000") results in the following error: java.time.format.DateTimeParseException: Text '2016-08-24T18:38:05.507+0000' could not be parsed at index 23 On the other…
Ryan Russell
  • 500
  • 4
  • 9
7
votes
4 answers

Parsing ISO-8601 DateTime with offset with colon in Java

I have a trouble with parsing date time in java, I have a strange date time format. How can I parse 2013-04-03T17:04:39.9430000+03:00 date time in java to format dd.MM.yyyy HH:mm in java?
vtokmak
  • 1,496
  • 6
  • 35
  • 66
6
votes
2 answers

ZonedDateTime format and parsing exception with “z” in format pattern

I have a problem with parsing ZonedDateTime: DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-ddzhh:mm"); ZonedDateTime.parse(s, formatter); This results in an error: java.time.format.DateTimeParseException: Text…
1 2
3
28 29