Help with date/time - I am going nuts...

moster67

Expert
Licensed User
Longtime User
I have run into the wall and my brain can't cope anylonger :)

I think I need some help...my maths today is not working nor is my locigal thinking :)

I am adding a timer-event in the future which must be expressed in ticks without milliseconds. I need to set a Start-Date and a Start-Time.

For example:
Start-Day: Sunday Feb 12, 2012
Start-Time: 23:00

Using a online-converter, Sunday Feb 12, 2012 (23:00) would become 1329084000

which can be calculated as follows:
Sunday Feb 12, 2012 (00:00) = 1329001200
23 hours = 82800 (3600 seconds * 23 hours)
1329001200 + 82800 = 1329084000

Those are my reference-data so I know how the ticks should look like.

I am getting the date and the hours using the Dialogs-library.
User-inputs:
date: 12/02/2012
hour: 23:00:00

Anyone who is willing to show me the code necessary to obtain 1329084000 ?

Thanks!
 

moster67

Expert
Licensed User
Longtime User
To me nothing is a dumb question (at least in the state my brain is in now) :D

No, it is not a service. My app sets a timer-event on a satellite-decoder (running under Linux) and therefore I need to pass on the dates in Epoch & Unix Timestamps (which are our ticks less milliseconds).

Here is a converter-tool I am using and so you can get an idea what I am talking about:

Epoch Converter - Unix Timestamp Converter
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Here is part of it:
B4X:
t = DateTime.TimeParse("23:00:00")-DateTime.timeParse("00:00:00")
Log(t)
t= t/DateTime.TicksPerSecond 
Log(t)

EDIT:
Added more:
B4X:
k = DateTime.DateParse("02/12/2012")-DateTime.DateParse("01/01/1970")
t = DateTime.TimeParse("23:00:00")-DateTime.timeParse("00:00:00")
k = k/DateTime.TicksPerSecond 
t= t/DateTime.TicksPerSecond 
Log(k+t)

Only I dont know how to show it as an integer in the logs.

EDIT:
Also your calculations are wrong: Sunday Feb 12, 2012 (00:00) = 1329001200
according to the website this is: 1329004800
[unless timezones will affect these?]
actually my code returns: 1,329,008,400 for the same date!
about 1 hour off target?
 
Last edited:
Upvote 0

moster67

Expert
Licensed User
Longtime User
@thedesolatesoul

Thank you very much for your time helping me. Your code-snippets were exactly what I was looking for.

To your code, I added a check for "DateTime.TimeZoneOffset" and modified final output accordingly. Now I am able to pass on the dates and times in Unix Timestamp-format to the decoder and everything works :)

In the next days, I will check if I need to take into consideration also Daylight Saving settings or not.

BTW: We surely got different results due to being in different time-zones. However, UTC should be the same.
 
Upvote 0
Top