-2

enter image description here I have been trying to convert a given date and time into milliseconds as I want to upload it as a timestamp but this is giving me Exception "java.time.format.DateTimeParseException: Text '2019/2/29 17:59:00' could not be parsed at index 5" . I had also tried the tradition way of SimpleDatePickr as well which showed a out of bond exception. I can't really figure out what's going on . I know this question has been previously answered but try to understand that none of them worked for me.

  • Possible duplicate of [Convert LocalDate in DD/MM/YYYY LocalDate](https://stackoverflow.com/questions/54896499/convert-localdate-in-dd-mm-yyyy-localdate) – Ole V.V. Feb 28 '19 at 11:39
  • When you can use `LocalDateTime` and the other classes from java.time (from API level 26/Oreo), don’t use `Timestamp` unless you indispensably need one for a legacy API that you cannot change or don’t want to change just now. If you have got year, month, etc., as numbers, avoid parsing altogether: `LocalDateTime.of(year, month, day, hour, minute)`. If you do need conversion: `Timestamp.from(yourInstant)`. – Ole V.V. Feb 28 '19 at 11:46
  • BTW you may use java.time on lower versions too if you add [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP) to your project and import the date-time classes from `org.threeten.bp`. – Ole V.V. Feb 28 '19 at 11:48

1 Answers1

0

You're time format is expecting a double digit number as month while you are feeding it a single number 2. Try to zero-pad your month like this: 2019/02/29 17:59:00

2hamed
  • 8,719
  • 13
  • 69
  • 112