Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  2.  
  3. long mnSeconds;
  4. long mnNanoseconds;
  5.  
  6. public static String format(long mnSeconds, long mnNanoseconds) {
  7. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.");
  8. return sdf.format(new Date(mnSeconds*1000))
  9. + String.format("%09d", mnNanoseconds);
  10. }
  11.  
  12. 2012-08-08 19:52:21.123456789
  13.  
  14. public static String format(long mnSeconds, long mnNanoseconds) {
  15. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  16. return sdf.format(new Date(mnSeconds*1000 + mnNanoseconds/1000000));
  17. }
  18.  
  19. long epoch = System.currentTimeMillis();
  20.  
  21. System.out.println("Epoch : " + (epoch / 1000));
  22.  
  23. Instant // Represent a moment in UTC.
  24. .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).
  25. .plusNanos( mnNanoseconds ) // Add on a fractional second as a count of nanoseconds. Returns another `Instant` object, per Immutable Objects pattern.
  26. .toString() // Generate text representing this `Instant` object in standard ISO 8601 format.
  27. .replace( "T" , " " ) // Replace the `T` in the middle with a SPACE.
  28. .replace "Z" , "" ) // Remove the `Z` on the end (indicating UTC).
  29.  
  30. long mnSeconds = … ;
  31. long mnNanoseconds = … ;
  32.  
  33. Instant instant = Instant.ofEpochSecond( mnSeconds ).plusNanos( mnNanoseconds );
  34.  
  35. Instant instant = Instant.ofEpochSecond( mnSeconds , mnNanoseconds );
  36.  
  37. String output = instant.toString();
  38.  
  39. new java.util.Date(mnSeconds);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement