Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • In my current scenario i had saved Ticks value calculated in C#; now what i want is read that tick value and get the same date in Java. Commented Sep 14, 2010 at 5:37
  • 1
    @Asoo: Okay. Walking to work ATM - code in twenty minutes. Basically divide by ticks per millisecond and subtract an offset. You should also bear timezone offsets in mind. Commented Sep 14, 2010 at 5:41
  • Thanks @Skeet....But if i want to calculate the ticks in Java and read them in C#.....i tried this but it does not gives the identical value: TimeZone utc = TimeZone.getTimeZone("UTC"); Calendar calendar = Calendar.getInstance(utc); calendar.set(2010,8,14,0,0,0); System.out.println(calendar.getTimeInMillis() * TICKS_PER_MILLISECOND + TICKS_AT_EPOCH); Commented Sep 14, 2010 at 6:27
  • @Asoo: It looks like it's keeping the existing millis-in-second value - call calendar.set(Calendar.MILLISECOND, 0); before the other call to calendar.set(). I'll update my answer. Commented Sep 14, 2010 at 6:39
  • There's a tiny, tiny, tiny improvement you could make, if you added 5000 to (ticks - TICKS_AT_EPOCH) before you divide by TICKS_PER_MILLISECOND. Then you'd be rounding to the nearest millisecond instead of truncating down. Commented Mar 5, 2015 at 2:51