BDR BDR - 1 year ago 101
Scala Question

Convert microseconds string to date in Java or Scala

how to convert timestamp(in microseconds) string to date in Java/Scala.
My goal is to compare two timestamps and find the differences between them.
I'm using java 8 and example Timestamp string is 1474457086337977.
I would like to convert this into Date or Timestamp instance.

Answer Source

Well, what about converting those microseconds to milliseconds and then just create a timestamp object?

long microsecs = 1474457086337977L;
long millis = TimeUnit.MILLISECONDS.convert(microsecs, TimeUnit.MICROSECONDS);
Timestamp time = new Timestamp(millis);

Wouldn't that work?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download