Does DateTime.Now return the ticks since 1/1/1970 to GMT time or UTC, or to the time on the device in question?
I send the current time to my external device for storage, like this:
The function called looks like this:
Then at some stage I read the stored date back from the device:
The function looks like this:
It all works fine for me in the UK, but someone is testing my app in the USA. Their tablet's time is set 12PM, EST in settings.
They store the time at 12:02, and it reads back as 06:02.
I'm having a bit of a struggle wrapping my head around it.
I send the current time to my external device for storage, like this:
B4X:
'now convert the time into it's parts
Dim timenow As Long = DateTime.Now
Dim calTime As spiroTime
calTime = Types.getDateFromTicks(timenow)
buf = Array As Byte(calTime.s,calTime.m,calTime.h,calTime.d,calTime.mo,calTime.y)
out.WriteBytes(buf,0,6)
The function called looks like this:
B4X:
Sub getDateFromTicks(intime As Long) As spiroTime
Dim outtime As spiroTime
outtime.y = DateTime.GetYear(intime)-2000 'DateTime works from 1970, my device dates work from 2000
outtime.mo = DateTime.GetMonth(intime)
outtime.d = DateTime.GetDayOfMonth(intime)
outtime.h = DateTime.GetHour(intime)
outtime.m = DateTime.GetMinute(intime)
outtime.s = DateTime.GetSecond(intime)
Return outtime
End Sub
Then at some stage I read the stored date back from the device:
B4X:
UnitInfo.Calibdate = Types.getDateInTicks(pk.pData(52),pk.pData(53),pk.pData(54),pk.pData(55),pk.pData(56),pk.pData(57))
The function looks like this:
B4X:
Sub getDateInTicks(s As Int, m As Int, h As Int, d As Int, mo As Int, y As Int) As Long
Dim result As Long
result = s * DateTime.TicksPerSecond
result = result + ( m * DateTime.TicksPerMinute)
result = result + (h-1) * DateTime.TicksPerHour
result = result + (d-1) * DateTime.TicksPerDay
Dim mn, yr As Int
mn = mo-1
yr = y+30 'DateTime works from 1970, my device dates work from 2000
result = DateTime.Add(result,yr,mn,0)
Return result
End Sub
It all works fine for me in the UK, but someone is testing my app in the USA. Their tablet's time is set 12PM, EST in settings.
They store the time at 12:02, and it reads back as 06:02.
I'm having a bit of a struggle wrapping my head around it.