Android Question DateTime.DateTimeParse() in local timezone?

Inman

Well-Known Member
Licensed User
Longtime User
I am trying to get the tick value of a date and time string. This is what I did.
B4X:
DateTime.DateFormat="dd MMMM yyyy"
DateTime.TimeFormat="H:mma"
Log(DateTime.DateTimeParse("19 May 2014","1:06PM"))

The tick value I am getting is 1:06PM in UTC. I would like to get the value for 1:06PM in the device's timezone. I need it to schedule a service, for which I believe we should use the tick value of the device's timezone in StartServiceAt().

Can this be done?
 

Inman

Well-Known Member
Licensed User
Longtime User
Yes I checked. I set the device timezone (from Android system settings, not within the app) to GMT+05:30 (which is IST). I added a Log(DateTime.TimeZoneOffset) just above the DateTimeParse and the log says 5.5. So the timezone is right.

Now I tried these:
B4X:
Log(DateTime.TimeZoneOffset)
Log(DateTime.Now)
Log(DateTime.DateTimeParse("19 May 2014","3:08PM"))

I got the following in log
B4X:
5.5
1400492309101
1400438280000
I used 3:08PM because that is what the time now in IST. So basically DateTime.Now and DateTime.DateTimeParse("19 May 2014","3:08PM") should give tick values that are close to each other (ignoring the seconds). 1400492309101 is 19/5/2014 15:08:29 GMT+5.5, which is correct as it came from DateTime.Now, but 1400438280000 is 19/5/2014 00:08:00 GMT+5.5.

I don't understand why this happens.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Oh my! I must have been through that document a hundred times in the last few weeks and yet I missed something so important :(

Thanks Erel
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Or put 2 'H'

DateTime.DateFormat="dd-MM-yyyy"
DateTime.TimeFormat="HH:mm" 'HH instead of only one H
Log(DateUtils.TicksToString(DateTime.DateTimeParse("19-05-2014","22:06")))
 
Upvote 0
Top