Java Converting 19-digit Unix Timestamp to a Readable Date

2019-05-23T22:07:33

I am trying to convert 19 digit Unix timestamp such as 1558439504711000000 (one and a half quintillion) into a readable date/time format. My timestamp ends with 6 zeros which suggests the time is in nano seconds.

I have come across some examples where people have used time zones which I don't need. Another example uses ofEpochSecond like so:

Instant instant = Instant.ofEpochSecond(seconds, nanos);

But I am not sure whether I need to use ofEpochSecond.

The code below gives my most recent approach of achieving this:

String timeStamp = "1558439504711000000";
long unixNanoSeconds = Long.parseLong(timeStamp);
Date date = new java.util.Date(timeStamp*1000L); 
// My preferred date format
SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy HH:mm:ss");                    
String formattedDate = sdf.format(date);
System.out.println("The timestamp in your preferred format is: " +  formattedDate); 

But the output I get is something like this:

// The timestamp in your preferred format is: 11-12-49386951 11:43:20

Which does not show the year format in e.g. 2019 format.

Copyright License:
Author:「mrT」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/56277090/java-converting-19-digit-unix-timestamp-to-a-readable-date

About “Java Converting 19-digit Unix Timestamp to a Readable Date” questions

I am trying to convert 19 digit Unix timestamp such as 1558439504711000000 (one and a half quintillion) into a readable date/time format. My timestamp ends with 6 zeros which suggests the time is i...
The database query is returning the date and time in a unix timestamp. I am trying to use clojure to convert this into human readable time and then split the date and time into two separate columns...
I have a string representing a unix timestamp (i.e. "1284101485") in Python, and I'd like to convert it to a readable date. When I use time.strftime, I get a TypeError: >>>import...
I have a string representing a unix timestamp (i.e. "1284101485") in Python, and I'd like to convert it to a readable date. When I use time.strftime, I get a TypeError: >>>import...
I have a string representing a unix timestamp (i.e. "1284101485") in Python, and I'd like to convert it to a readable date. When I use time.strftime, I get a TypeError: >>>import...
I have an Unix timestamp (with microsecond precision) value in 1.514408397505346E9. What is the correct way to convert it to readable date time format? Is it correct to convert like below? java.u...
Is there a MySQL function which can be used to convert a Unix timestamp into a human readable date? I have one field where I save Unix times and now I want to add another field for human readable d...
I'm working with flask and handsontable. I'm interested in dynamically creating data and then passing it to a view for display with handsontable. So far I have : @app.route('/mv') def my_view(): ...
How can human readable date time format(yyyy.mm.dd hh:mm:ss ) be converted into Unix timestamp? For example I have following date 2019.07.12 08:00:00 that need to be converted into unix time forma...
i am tring to convert this unix timestamp 1491613677888 to readable date. found here (stackoverflow) that python script: import datetime print( datetime.datetime.fromtimestamp( int("128410...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.