Android Question Problem in Date Time - (Ticks)

M Zuhri

Member
Licensed User
Hello all,
In my web service, i need to pass the ticks for the given date as a parameter. so i use the b4a ' ticks' value, but it makes the problem there. thing is, lets say as of today(30/08/2019), b4a ticks shows as '1567103400000' but
in my .net application same date gives me '637027200000000000' ticks. I m totally confused. can anyone kindly help me to sort things out please.

Regards
 

DonManfred

Expert
Licensed User
A tick in B4X is a millisecond (a 1000th of a second).

A tick in vb.net is
https://docs.microsoft.com/en-us/dotnet/api/system.datetime.ticks?view=netframework-4.8

A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second.

The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 (0:00:00 UTC on January 1, 0001, in the Gregorian calendar), which represents DateTime.MinValue. It does not include the number of ticks that are attributable to leap seconds.

Edit to add:
https://stackoverflow.com/questions/3706306/c-sharp-datetime-ticks-equivalent-in-java
 

emexes

Well-Known Member
Licensed User
Manfred has answered your question, but I'd just like to add this website that I've found useful for understanding/checking B4A DateTimes:

https://currentmillis.com/tutorials/system-currentTimeMillis.html

It has a conversion feature (UTC on left, your local time zone on right) plus a good visual explanation of:

2 persons calling System.currentTimeMillis() at the same time should get the same result no matter where they are one the planet
 

M Zuhri

Member
Licensed User
Thanks for @manfred, @emexes for your help.
I followed @manfred's reference in stackoverflow, where i found some useful tips, a constant value to be added with b4a ticks * 10000, it means, in order to get 31/08/2019 we need to pass ((1567189800000 * 10000) + 621355968000000000L), but strange thing is, it give us 30/0/2019 in .net, so i change it to
((1567189800000 * 10000.5) + 621355968000000000L) , then and only it gave me the correct date. Can I fellow this step or am i making mistake in some where ???
 

OliverA

Expert
Licensed User
Integer overflow in your first multiplication. Put an L on the first number (starting with 156...)
 
Top