Android Question DateTime question is driving me crazy [Solved]

Gaxapu

Member
Licensed User
Hello.

After read some threads in the forum about datetime related questions, I'm yet unable to understand why the next sentence:
Log(DateTime.Time(DateTime.TicksPerMinute * 30))
gives "1:30:00" instead of "00:30:00"

Can anyone, please, explain me?
 

JordiCP

Expert
Licensed User
Longtime User
Perhaps it is because of the time offset in your zone? (UTC+1)

You can check/comfirm it with

Log(DateTime.Time(0))
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
gives "1:30:00" instead of "00:30:00"

Your code should be like this:
B4X:
Dim p As Period =DateUtils.PeriodBetween(0, DateTime.TicksPerMinute * 30)   'need dateutils library
    Log($"$2.0{p.Hours}:$2.0{p.Minutes}:$2.0{p.Seconds}"$)
DateTime.Time(DateTime.TicksPerMinute * 30) is an instance of time at a given old date many decades ago.
 
Last edited:
Upvote 0

Gaxapu

Member
Licensed User
Your code should be like this:
B4X:
Dim p As Period =DateUtils.PeriodBetween(0, DateTime.TicksPerMinute * 30)   'need dateutils library
    Log($"$2.0{p.Hours}:$2.0{p.Minutes}:$2.0{p.Seconds}"$)
DateTime.Time(DateTime.TicksPerMinute * 30) is an instance of time at a given old date many decades ago.

So, should I use "Period" to maintain, and make calculations over, just the Hour:Minute (for a day schedule) ?

Also, I´m intrigued about the notation you used in log. Could you point me to learn more about it?

Tnx a lot.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
should I use "Period" to maintain, and make calculations over, just the Hour:Minute (for a day schedule) ?
Here is a code snippet that Erel prefers to the one I posted I think, that will do what you are looking for:

´m intrigued about the notation you used in log. Could you point me to learn more about it?
Here is the tutorial by Erel on Smart String Literals:
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Please use [code]code here...[/code] tags when posting code.
2. This code is completely wrong: Log(DateTime.Time(DateTime.TicksPerMinute * 30))
It is explained in the date and time video tutorial: https://www.b4x.com/etp.html
Well worth watching if you are working with dates and times.

If you want to convert milliseconds to string then follow the link @Mahares posted above.
 
Upvote 0
Top