2

Possible Duplicate:
C# DateTime.Ticks equivalent in Java

hello guys

can anybody tell me how to convert date to .Net ticks in java. any help will be appreciative.

thanks

Community
  • 1
  • 1
sajjoo
  • 6,576
  • 20
  • 65
  • 86
  • 2
    I'd say many Java do not know what .net ticks means. In case you do, you should explain. – maaartinus Jan 20 '11 at 16:34
  • looks like Jon Skeet's answer solves the problem! – CoolBeans Jan 20 '11 at 16:37
  • @jarnbjo its giving the solution of converting ticks to date. I need to convert a date time into ticks. – sajjoo Jan 20 '11 at 16:38
  • @saijjo: So reversing the calculation in the response from `(ticks - TICKS_AT_EPOCH) / TICKS_PER_MILLISECOND` to `TICKS_AT_EPOCH + javaTime * TICKS_PER_MILLISECOND` was an unreasonable task for you? Alternatively, you could have read the comments to Jon's response to find out that someone had done that job for you already. – jarnbjo Jan 20 '11 at 18:00

3 Answers3

12

ticks = 621355968000000000L+javaMillis*10000;

bestsss
  • 11,796
  • 3
  • 53
  • 63
1

You may also want to check the icu4j library from the ICU project especially the UniversalTimeScale class which is similar to .Net ticks.

gabuzo
  • 7,378
  • 4
  • 28
  • 36
0

DateTime.Ticks Property The value of this property is the number of 100-nanosecond intervals that have elapsed since 12:00 A.M., January 1, 0001.

Date.getTime() Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Accounting for the 1970 years offset and multiplying by ten seems to be the solution.

Community
  • 1
  • 1
maaartinus
  • 44,714
  • 32
  • 161
  • 320