Epoch Date/Time Conversion

Bernd68

Member
Licensed User
Longtime User
I get a strange result, when i try to convert an Epoch Timestamp.

Using this code
B4X:
 Dim Starttime As Long
 Dim StartTimeText  As String
 DateTime.TimeFormat = "mm/dd/yy hh:mm:ss"
 Starttime = 1332534073
 StartTimeText = DateTime.Time(Starttime*1000)
 Log("EPOCH converted to: "& StartTimeText)

I get the follwing result in the LogViewer:

EPOCH converted to: 21/23/12 09:21:13

The Time is correct, but the Date is wrong. Do i miss something here ?

Bernd
 

Bernd68

Member
Licensed User
Longtime User
One more question

How would i calculte the EPOCH timestamp with B4A

Does anyone already have a solution for it?

Rgds Bernd
 
Upvote 0

Bernd68

Member
Licensed User
Longtime User
DateTime Format Problem

It is right for "Now".

But, how would it be possible for a given Date?

I tried the following code:

B4X:
    DateTime.DateFormat = "MM/dd/yy hh:mm:ss H"
   Dim UTC_TS As Long 
   UTC_TS = DateTime.DateParse("03/23/2012 19:30:00") - DateTime.DateParse("01/01/1970 00:00:00")
   Log("UTC_TS: "&UTC_TS)

But this throws an ParseExeption "Unparsable Date", because of "H" in the DateFormat.

Following the THIS Documentation Link for "Formats", this should be allowed.

Looking for a solution to get the UTC Timestamp for a given Date & Time for an 24h Format

Any ideas?

Rgds Bernd
 
Upvote 0

Bernd68

Member
Licensed User
Longtime User
Yes i saw it, and changed it as following

B4X:
    DateTime.DateFormat = "MM/dd/yy hh:mm:ss H"
   Dim UTC_TS As Long 
   UTC_TS = DateTime.DateParse("03/23/2012 19:30:00 H") - DateTime.DateParse("01/01/1970 00:00:00 H")
   Log("UTC_TS: "&UTC_TS)

But still throws an ParseExeption "Unparsable Date".
Do i miss something ?
 
Upvote 0
Top