Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Timestamp to Date not correct in java

I am trying to convert the timestamp to date in java but I got an old date

Result Tue Jan 20 06:13:12 IST 1970

Expected:
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is my code

   public static void main(String args[]){    
            Date date=new Date(1644192000);  
            System.out.println(date);                     
    } 

>Solution :

The Date class is mostly obsolete except for backwards compatibility. Instead, use the modern java.time classes:

Instant timestamp = Instant.ofEpochSecond(1644192000);
// note the second/millis difference Rob Spoor mentioned
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading