-2

Date format coming from the database: 1629777600000

SimpleDateFormat simpleDateFormatter = new SimpleDateFormat("MM/dd/yyyy");

simpleDateFormat.format(1629777600000);

When using this simple date format I am not able to convert 1629777600000 to a viewable date

OldProgrammer
  • 12,050
  • 4
  • 24
  • 45
  • what is `1629777600000` time in millis since epoch time? – jmj Aug 30 '21 at 17:44
  • Does this answer your question? [Getting "unixtime" in Java](https://stackoverflow.com/questions/732034/getting-unixtime-in-java) – Joakim Danielson Aug 30 '21 at 17:45
  • @jmj Yes, that is what I am trying to determine as well. Its coming from Oracle SQL database – halfpenny-ian Aug 30 '21 at 17:46
  • Use java.time, the modern Java date and time API. `Instant.ofEpochMilli(1_629_777_600_000L).atZone(ZoneId.of("America/New_York")).toLocalDate().format(DateTimeFormatter.ofPattern("MM/dd/yyyy"))`. Yields `08/24/2021`. – Ole V.V. Aug 31 '21 at 12:56
  • I recommend you don’t use `SimpleDateFormat`. That class is notoriously troublesome and long outdated. Instead use `DateTimeFormatter` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Aug 31 '21 at 14:34
  • Does this answer your question? [Convert ms into a string date with Java 8](https://stackoverflow.com/questions/32837406/convert-ms-into-a-string-date-with-java-8). Sorry that I was too slow to close your question as a duplicate before others closed it otherwise. It may also be that it should better have been closed as caused by a typo, though? – Ole V.V. Aug 31 '21 at 20:18

1 Answers1

1
SimpleDateFormat simpleDateFormatter = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(simpleDateFormatter.format(1629777600000L));

Print: 08/24/2021


But your code does not compile:

  • you initialize simpleDateFormatter but use simpleDateFormat (without ter)
  • 1629777600000 is a Long, therefore it needs an L at its end

I think the L problem is just from modifiying the code for the stackoverflow question. But the variable name is maybe a real problem in your code.

Ralph
  • 118,862
  • 56
  • 287
  • 383