0

C# has Datetime.FromBinary(long) method which accepts long. I have long data = -8587633342590756227. Datetime.FromBinary(-8587633342590756227) which gives {7/30/2015 10:10:26 AM}. How to convert it to date-time format in Java?

Thanks

Unheilig
  • 16,196
  • 193
  • 68
  • 98
Poonam E
  • 159
  • 2
  • 8
  • 1
    Can I suggest not storing/transmitting data in what is effectively a .NET-centric format to start with? Beyond that - look at the documentation for `DateTime.FromBinary`, which explains what the value is. Note that Java's `Date` doesn't have as much precision as `DateTime`, although `java.time.Instant` does (and more). – Jon Skeet Jul 29 '15 at 18:11
  • is it the one you are looking for ? http://stackoverflow.com/questions/23670516/what-is-the-equivalent-of-datetime-fromoadate-in-java-double-to-datetime-in-j – Jegg Jul 29 '15 at 18:19
  • No, that's a different one I guess – Poonam E Jul 29 '15 at 18:35

1 Answers1

0

The value .Net (de-)serializes via To-/FromBinary seems very specific to .Net, so I don't think there's an easy way to convert that value into a java.util.Date.

The easiest way I can think of from the perspective of a Java developer would be to convert your .Net DateTime to Unix time (see DateTimeOffset.ToUnixTimeMilliseconds) and then use that value for the java.util.Date constructor that accepts that value.

kjosh
  • 587
  • 4
  • 11