0

I am using DateTimeFormatter in my code for parsing the timestamp. I have timestamp like 01-JAN-21 10.10.10.100000 AM and looking at this website https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html I tried with the pattern: dd-LLL-yy hh.mm.ss.SSSSSS a which isn't working. I get illegal pattern component "LLL". I also tried with dd-MMM-yy hh.mm.ss.SSSSSS a but the data isn't parsed.

How should the pattern look like?

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
T.M.
  • 1
  • which type of Date you want to generate from your Timestamp? it can be Date, LocalDateTime, LocalDate... – Sobhan Oct 11 '21 at 07:49
  • What would it be the difference by Date and LocalDate? – T.M. Oct 11 '21 at 08:26
  • you can find your answer about differences between Date and LocalDate here: https://stackoverflow.com/questions/60144827/difference-between-java-util-date-and-java-time-localdate-in-java – Sobhan Oct 11 '21 at 08:59
  • What is your suggestion for a timestampformat in case I want to generate "Date" and in case I want to generate "LocalDate"? – T.M. Oct 11 '21 at 09:43
  • take a look at this answer, it is a complete answer and I think you can solve your issue with this, also a bit creativity is needed, update me if you could not solve your issue with this one, i can help you more, GL: https://stackoverflow.com/a/4216767/7189597 – Sobhan Oct 11 '21 at 13:43
  • 1
    The second pattern, `dd-MMM-yy hh.mm.ss.SSSSSS a`, looks right to me. A [mre] will help us find out what’s wrong. Remember to specify exactly what goes wrong. Paste any error message that you see into your question. – Ole V.V. Oct 12 '21 at 13:49
  • 1
    I recommend you don’t use `Date`. That class is poorly designed and long outdated. Use `LocalDateTime` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). A `LocalDate` can hold only the date part. For a timestamp I assume you also need the time-of-day part, therefore `LocalDateTime`. – Ole V.V. Oct 12 '21 at 13:55

0 Answers0