Android Question TimeStamp calculation

KPmaster

Member
Licensed User
Hi all,
in my app I need to use the TimeStamp for a given date, and I'm using some code like this sample

B4X:
Dim startdateformat as String = DateTime.DateFormat
Dim starttimeformat as String = DateTime.TimeFormat
Dim MyTimeStamp as Long

DateTime.DateFormat = "yyyy-MM-dd"
DateTime.TimeFormat = "HH:mm:ss"
MyTimeStamp = DateTime.DateTimeParse("2014-09-17", "10:28:30")

The value of MyTimeStamp is 1410942510000, that is not correct because it should be 1410949710.
What I'm doing wrong?
 

Mahares

Expert
Licensed User
@KPmaster: Your code is correct. The correct answer is: 1410942510000
In fact if you reverse it you get this:
B4X:
Dim MyDate As String
MyDate=DateUtils.TicksToString(1410964110000)
Log(MyDate) 'displays 2014-09-17  10:28:30
 
Upvote 0

Mahares

Expert
Licensed User
@eps: the code I posted makes the following point: If you start with the timestamp and work backwards to calculate the string, you will get the date and time as I showed.
The point is; There is nothing wrong with KPmaster's code.
 
Upvote 0

KPmaster

Member
Licensed User
I'm trying to compose an html command to access the events stored in a Mobotix camera, and I've found a website (http://www.onlineconversion.com/unix_time.htm) where calculate the TimeStamp, and the value from the website is different, and I was trying to understand why.

Reading Mobotix API, I've found this, but TimeStamp values are not working and every search give an empty result:
searchbytime_start= Escaped stringTime Search Starting Time
Request an image via its timestamp [seconds.microseconds] since the Epoch (00:00:00 UTC, January 1, 1970).
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
If you are looking for 1410949710 as your answer you need to follow the below code: Please note that the web site you refer to calculates the seconds, B4A calculates the Milliseconds. The code below converts the milliseconds to secs and ignores time zone:
B4X:
DateTime.DateFormat = "yyyy-MM-dd"
DateTime.TimeFormat = "HH:mm:ss"
Dim MyTimeStamp As Long
DateTime.SetTimeZone(0)
MyTimeStamp = DateTime.DateTimeParse("2014-09-17", "10:28:30")/1000
Log(MyTimeStamp) 'displays what you are looking for which is: 1410949710
 
Upvote 0

KPmaster

Member
Licensed User
Thank you guys.
Now I'm investigating about the "seconds.microseconds" of the API, trying to understand how to pass the correct value to the Mobotix camera.
When finally I will find it, I will post here the solution.
 
Upvote 0

KPmaster

Member
Licensed User
Solved.
In fact, what I need is only the
B4X:
MyTimeStamp = DateTime.DateTimeParse("2014-09-17", "10:28:30")/1000
because Mobotix settings are already in my TimeZone, so I don't need to set it to 0.
 
Upvote 0
Top