Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
- long mnSeconds;
- long mnNanoseconds;
- public static String format(long mnSeconds, long mnNanoseconds) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.");
- return sdf.format(new Date(mnSeconds*1000))
- + String.format("%09d", mnNanoseconds);
- }
- 2012-08-08 19:52:21.123456789
- public static String format(long mnSeconds, long mnNanoseconds) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
- return sdf.format(new Date(mnSeconds*1000 + mnNanoseconds/1000000));
- }
- long epoch = System.currentTimeMillis();
- System.out.println("Epoch : " + (epoch / 1000));
- Instant // Represent a moment in UTC.
- .ofEpochSecond( mnSeconds ) // Determine a moment from a count of whole seconds since the Unix epoch of the first moment of 1970 in UTC (1970-01-01T00:00Z).
- .plusNanos( mnNanoseconds ) // Add on a fractional second as a count of nanoseconds. Returns another `Instant` object, per Immutable Objects pattern.
- .toString() // Generate text representing this `Instant` object in standard ISO 8601 format.
- .replace( "T" , " " ) // Replace the `T` in the middle with a SPACE.
- .replace "Z" , "" ) // Remove the `Z` on the end (indicating UTC).
- long mnSeconds = … ;
- long mnNanoseconds = … ;
- Instant instant = Instant.ofEpochSecond( mnSeconds ).plusNanos( mnNanoseconds );
- Instant instant = Instant.ofEpochSecond( mnSeconds , mnNanoseconds );
- String output = instant.toString();
- new java.util.Date(mnSeconds);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement