I Inman Well-Known Member Licensed User Longtime User May 19, 2014 #1 I am trying to get the tick value of a date and time string. This is what I did. Code: Copy 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?
I am trying to get the tick value of a date and time string. This is what I did. Code: Copy 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?
Erel B4X founder Staff member Licensed User Longtime User May 19, 2014 #2 DateTimeParse uses the local timezone. Are you sure that you are not calling SetTimeZone somewhere in your code? Upvote 0
DateTimeParse uses the local timezone. Are you sure that you are not calling SetTimeZone somewhere in your code?
I Inman Well-Known Member Licensed User Longtime User May 19, 2014 #3 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: Code: Copy Log(DateTime.TimeZoneOffset) Log(DateTime.Now) Log(DateTime.DateTimeParse("19 May 2014","3:08PM")) I got the following in log Code: Copy 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
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: Code: Copy Log(DateTime.TimeZoneOffset) Log(DateTime.Now) Log(DateTime.DateTimeParse("19 May 2014","3:08PM")) I got the following in log Code: Copy 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.
Erel B4X founder Staff member Licensed User Longtime User May 19, 2014 #4 What is the value of: Code: Copy Dim t As Long = DateTime.DateTimeParse("19 May 2014","3:08PM") Log(DateUtils.TicksToString(t)) 'add reference to DateUtils library Upvote 0
What is the value of: Code: Copy Dim t As Long = DateTime.DateTimeParse("19 May 2014","3:08PM") Log(DateUtils.TicksToString(t)) 'add reference to DateUtils library
I Inman Well-Known Member Licensed User Longtime User May 19, 2014 #5 I got 19 May 2014 0:08AM Upvote 0
Erel B4X founder Staff member Licensed User Longtime User May 19, 2014 #6 The problem is in the time format you created. It should be: Code: Copy DateTime.DateFormat="dd MMMM yyyy" DateTime.TimeFormat="h:mma" 'small h instead of H Log(DateUtils.TicksToString(DateTime.DateTimeParse("19 May 2014","1:06PM"))) http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html Upvote 0
The problem is in the time format you created. It should be: Code: Copy DateTime.DateFormat="dd MMMM yyyy" DateTime.TimeFormat="h:mma" 'small h instead of H Log(DateUtils.TicksToString(DateTime.DateTimeParse("19 May 2014","1:06PM"))) http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
I Inman Well-Known Member Licensed User Longtime User May 19, 2014 #7 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
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
netsistemas Active Member Licensed User Longtime User Oct 21, 2017 #8 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
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")))