Android Question Getting the "ticks" value for today's current time

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone.

I know that using the following code will return the "ticks" value for the current time for 1-Jan-1970.

B4X:
DateTime.Now

I would like to get the "ticks" value for the current time for "today". I need to use it with this coding which gets the "ticks" value for today.

B4X:
DateTime.TimeParse

How do I do it?

Thanks.
 

DonManfred

Expert
Licensed User
Longtime User
will return the "ticks" value for the current time for 1-Jan-1970
No. The Value of the ticks is the number of seconds since 1. jan 1970.

Datetime.Now will return NOW (TODAY)
No need to parse something. Datetime.Now can be used as datetime value (it´s a long)
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Don,

Can you check my coding? When I run the app if the start time is 23:00 and the end time is 23:59 I would expect the toast message to say the time now is outside the start and end times. That works but when I change the start time to 02:00 I still get a toast messages stating the same thing. Did I make a mistake on the coding?

B4X:
If kvs.get("UserDisabledMuteSunday") = False Then                 
   intStartTimeTicks = DateTime.TimeParse(kvs.Get("SundayRow1StartTime"))
   intEndTimeTicks = DateTime.TimeParse(kvs.Get("SundayRow1EndTime"))
                 
   If DateTime.Now >= intStartTimeTicks And DateTime.Now <= intEndTimeTicks Then
      ToastMessageShow("It's in between", False)
      RemuteSounds
   Else
      ToastMessageShow("It's outside the peroid", False)
      RestoreSounds
   End If
Else
   RestoreSounds
End If
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Don,

I checked DateTime.Now ticks is a huge number compared to the ticks value for 02:00 which was in SundayRow1StartTime. How do I just parse the time so I can get only the ticks value for the current time on today's date?

If you have time, can you change my coding so I can do the comparisons correctly?

Thanks so much.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
I tried this coding but intStartTimeTicks is still way too small.

B4X:
intStartTimeTicks = DateTime.DateTimeParse(DateTime.Date(DateTime.Now),kvs.Get("SundayRow1StartTime"))
 
Upvote 0
Top