B4J Question [SOLVED] DateTime ticks... to time (dumb question)

Magma

Expert
Licensed User
Longtime User
Hi there..

I want to use slider to move on time... so i ve created slider with max values of 86400 (seconds of day)

I know that ticks per day goes at 86400000 (millions)

So i am calculating *1000..

The code i am using is:
B4X:
    ttime.Text=DateTime.Time(Value*1000)
'value is from silder

The bad thing is when have 0 value return at textfield 02:00:00 - so i am thinking that may be use zone time..

What to do ? just subtract the time ? or there is a better way to check..
 

Cableguy

Expert
Licensed User
Longtime User
Use timeparse methods.
You also have ticks to minutes and minutes to ticks methods
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Each second is 1000 ticks, so each minute is 60 000 ticks, and so on...
Date time has methods that allow you to get the tick count from a string like "00H05m42s" and also can provide the time string from a ticks count...
Do explore the DateTime keyword and methods, they are what you need
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Oh i know that but i am telling other thing... i have a slider from 0 to 86400 (*1000) that represent ticks...

So when i am changing value to 0 - i want return time 00:00:00 but returns me 02:00:00 -- so the best way is to subtract it ? or do something else ..
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
B4X:
    Dim tt As Int
    tt=DateTime.TicksPerHour*2
    ttime.Text=DateTime.Time((Value*1000)-tt)

This works for me... don't know if in other time zone will have problem...


slider max value set it to 86399 (because starts from 0)
 
Upvote 0

Ed Brown

Active Member
Licensed User
Longtime User
I've just checked this too and you're right. It does include the timezone offset.

Change it to
B4X:
tt=DateTime.TicksPerHour * DateTime.TimeZoneOffset
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
you can try to use "settimezone" method...

something like (pseudo code)

dim gtz as datetime.gettimezone 'this way we can after reset the timezone
datetime.settimezone(0h) 'we set te timezone to 0
Do our maths here
datetime.settimezone = gtz ' we reset the timezone to its original value
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…