Android Question DateTime

Hakanunver

Member
Licensed User
I wait 0 as result but see 2 hour difference why ?

B4X:
Dim lo As Long = DateTime.Now - DateTime.TimeParse(DateTime.Time(DateTime.Now))
Log(DateTime.Time(lo))
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
DateTime.Time converts a ticks value to a string.
Ticks value = Number of milliseconds since 1/1/1970 00:00 UTC.

You cannot use DateTime.Time to convert a "duration" to a string.

1. Use DateUtils.PeriodBetween or PeriodBetweenInDays to correctly calculate the difference between two dates.
2. Convert the period to string with PeriodToString: https://www.b4x.com/android/forum/threads/convert-dateperiod-to-string.51046/#post-319385
This code assumes that the period is smaller than a day. Add a day field if needed.
 
Upvote 0
Top