Epoch timestamp problems

Kevin

Well-Known Member
Licensed User
Longtime User
I am reading a timestamp and length that is in Epoch (UDT). I can't for the life of me come up with the correct result. I am setting the StartTime manually in this example, but normally it comes from a JSON file. This sample number is an actual number I pulled from the file.

For example:

B4X:
Dim StartTime, EndTime, RunTime As Long
Dim StartTimeText, EndTimeText
StartTime = 1328461200
RunTime = 1800
EndTime = StartTime+RunTime
DateTime.TimeFormat = "h:mm a"
StartTimeText = DateTime.Time (StartTime)
EndTimeText = DateTime.Time (EndTime)
Msgbox (StartTimeText & " to " & EndTimeText,"")

I ran 1328461200 through an online Epoch converter and it came up with:

GMT: Sun, 5 Feb 2012 17:00:00 UTC
Your time zone: Sunday, February 05, 2012 11:00:00 AM GMT-6


Which is what it should be. I expect the output to say 11:00 AM to 11:30 AM and instead it comes up with 2:01 AM to 2:01 AM.

If I change the format to include the date....

B4X:
DateTime.TimeFormat = "MM/dd/yyyy h:mm a"


...then it comes up with 01/16/1970 2:01 AM to 01/16/1970 2:01 AM.

Clearly I am missing something basic here. :sign0104:

I would like it to return the correct time regardless of timezone or DST. Unfortunately I can't even get it in the right decade!
 

lagore

Active Member
Licensed User
Longtime User
Hi
The Epoch Date is in seconds from 1970 B4A works in milliseconds so multiply your value by 1000 then convert in in B4A. If you are doing this with SQLITE it works in seconds.
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
Thanks! It was indeed the milliseconds that I was missing. Multiplying by 1000 did the trick.
 
Upvote 0
Top