Questions tagged [date-parsing]

Date-parsing refers to programming logic which reads one or more parameters, attempts to match it to a supported or specified date format, then returns the resulting Date if successful.

References

494 questions
21
votes
4 answers

JDK8: unable to parse LocalTime

I managed to parse a String to a LocalDate object: DateTimeFormatter f1=DateTimeFormatter.ofPattern("dd MM yyyy"); LocalDate d=LocalDate.parse("26 08 1984",f1); System.out.println(d); //prints "1984-08-26" But I cannot do the same with LocalTime.…
Luigi Cortese
  • 10,841
  • 6
  • 37
  • 48
21
votes
5 answers

Parsing a date’s ordinal indicator ( st, nd, rd, th ) in a date-time string

I checked the SimpleDateFormat javadoc, but I am not able to find a way to parse the ordinal indicator in a date format like this: Feb 13th 2015 9:00AM I tried "MMM dd yyyy hh:mma", but the days have to be in number for it to be correct? Is it…
hao
  • 635
  • 2
  • 8
  • 20
14
votes
4 answers

Parsing dates without all values specified

I'm using free-form dates as part of a search syntax. I need to parse dates from strings, but only preserve the parts of the date that are actually specified. For instance, "november 1, 2010" is a specific date, but "november 2010" is the range of…
kevingessner
  • 18,559
  • 5
  • 43
  • 63
13
votes
3 answers

How can I make a leading zero in DateTime-Pattern optional

I have a user input field and would like to parse his date, whatever he puts in. The user might provide his date with a leading zero or without one, so I wanna be able to parse an input like this 02.05.2019 and also this 2.5.2019 But as far as I…
John Du
  • 247
  • 1
  • 2
  • 7
13
votes
2 answers

Java 8 DateTimeFormatter two digit year 18 parsed to 0018 instead of 2018?

With Java 8, the code below parses "18" into year "0018" instead of "2018". DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d/y"); return LocalDate.parse(date, formatter); input date is "01/05/18". 1) why the result is "0018"? Does…
Jesse Zhuang
  • 388
  • 1
  • 4
  • 14
13
votes
3 answers

Read csv with dd.mm.yyyy in Python and Pandas

I am reading a csv file with German date format. Seems like it worked ok in this post: Picking dates from an imported CSV with pandas/python However, it seems like in my case the date is not recognized as such. I could not find any wrong string in…
RogerWilco77
  • 319
  • 1
  • 3
  • 13
12
votes
3 answers

Why parsing a String into Date in Java is slow? Can we accelerate it?

I am reading a text file containing dates, and I want to parse the Strings representing the dates into Date objects in java. What I notice is the operation is slow. Why? is there any way to accelerate it? My file looks like: 2012-05-02 12:08:06:950,…
Rami
  • 8,044
  • 18
  • 66
  • 108
12
votes
7 answers

mustache.js date formatting

I have started using mustache.js and so far I am very impressed. Although two things puzzle me. The first leads on to the second so bear with me. My JSON {"goalsCollection": [ { "Id": "d5dce10e-513c-449d-8e34-8fe771fa464a", …
Dooie
  • 1,649
  • 7
  • 30
  • 47
11
votes
4 answers

Java 8 DateTimeFormatter parsing optional sections

I need to parse date-times as strings coming as two different formats: 19861221235959Z 1986-12-21T23:59:59Z The following dateTimeFormatter pattern properly parses the first kind of date strings DateTimeFormatter.ofPattern…
Cec
  • 1,726
  • 3
  • 18
  • 31
11
votes
2 answers

ZonedDateTimeDeserializer is missing in jackson jsr310

I'm parsing a ZonedDateTime using like this: @JsonSerialize(using = ZonedDateTimeSerializer.class) private ZonedDateTime expirationDateTime; I need to be able to properly deserialize this date. However, there is no deserializer for this that is…
dvelopp
  • 4,095
  • 3
  • 31
  • 57
11
votes
4 answers

Problem with date formats in JavaScript with different browsers

I am working with dates in an RSS feed, but am finding differing results when using the code below in IE, Chrome and Firefox: new Date('2001-01-01T12:00:00Z') Firefox is happy with that, but Chrome and IE return Invalid Date. I thought I'd try…
TimS
  • 5,922
  • 6
  • 35
  • 55
11
votes
3 answers

Parsing a date using DateTimeFormatter ofPattern

I'm trying to parse a string containing a date and time using the java.time.format.DateTimeFormatter (my ultimate goal is to get the date from this string into a java.time.LocalDate). I keep getting DateTimeParseExceptions when trying to parse the…
Chris
  • 839
  • 2
  • 10
  • 33
11
votes
2 answers

Joda time - Parsing string throws java.lang.IllegalArgumentException

Shouldn't a String formatted with a specific DateTimeFormatter be able to be parsed using LocalDateTime.parse()? Test DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis() LocalDateTime ldt = new LocalDateTime() String val =…
user800014
11
votes
6 answers

Fastest way to parse a date in Basic ISO 8601 format, using Java

When parsing a YYYYMMdd date, e.g. 20120405 for 5th April 2012, what is the fastest method? int year = Integer.parseInt(dateString.substring(0, 4)); int month = Integer.parseInt(dateString.substring(4, 6)); int day =…
user3001
  • 3,437
  • 5
  • 28
  • 54
10
votes
7 answers

Simpledateformat unparseable date

I have a String in a database (match.getDate) that has the following date format: 01/04/2018 This is the date I want to format, stored as day/month/year. I want to format this for my Android app. I want to format the date into: Sun 01 Apr…
Carl Bruiners
  • 516
  • 1
  • 7
  • 21
1
2
3
32 33