Difference in ticks in both versions and how to eliminate them

aj11

Member
Licensed User
Longtime User
I am using simultaneously HP Ipaq(Win mobile,B4PPC) and Sony reader(Android,B4A) for sending also date datas. Sorting is much easier with tics, but they are different in both versions.

Any suggestions how to equalize these in B4A to B4PPC?

Thanks in advance.
Ales
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Process_Globals
   Dim NET_TICKS_AT_EPOCH, NET_TICKS_PER_MILLISECOND As Long
   NET_TICKS_AT_EPOCH = 621355968000000000
   NET_TICKS_PER_MILLISECOND = 10000
End Sub

Sub ConvertNetToB4A(NetTicks As Long) As Long
   Return (NetTicks - NET_TICKS_AT_EPOCH) / NET_TICKS_PER_MILLISECOND
End Sub

Sub ConvertB4AToNet(Ticks As Long) As Long
   Return Ticks * NET_TICKS_PER_MILLISECOND + NET_TICKS_AT_EPOCH
End Sub

I haven't tested it so please do some tests yourself.

It is based on this solution: C# DateTime.Ticks equivalent in Java - Stack Overflow
 
Upvote 0

aj11

Member
Licensed User
Longtime User
Erel, as usual You have a solution.
It works, but I don't know why with this constant:
NET_TICKS_AT_EPOCH = 621356004000000000


Thanks
Ales
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
The epoch for ticks is (from the MSDN site)
The value of this property is the number of 100-nanosecond intervals that have elapsed since 12:00 A.M., January 1, 0001.
so the constant is the difference between the two epochs' eg 1970 years.
 
Upvote 0

aj11

Member
Licensed User
Longtime User
I know why constant, but for me it works with constant that is 36000000000 ticks greater. I suppose it is one hour from time zone or something like that..
 
Upvote 0
Top