Time zone I currently wrote in is USA - Eastern, but my application could be in use anywhere in the world - so I need to output the local date/time in UTC.What exactly do you mean with UTC format? What is the time zone of the date string you wrote?
lblUTCTime.Text = DateTime.Time(DateTime.Now - DateTime.TicksPerHour * TZOffset)
Public Sub GetTimeZoneOffset As Int
Dim s, d As String
Dim l As Long
s = DateTime.DateFormat
DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss"
l = DateTime.Now
d = DateTime.Date(l) & " GMT"
DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss z"
Dim res As Int
res = -Round((l - DateTime.DateParse(d))/3600000)
DateTime.DateFormat = s
Return res
End Sub
Thanks - this is good. I'll be able to use this for real time measurements.This will give you the GMT time for any local time.
B4X:lblUTCTime.Text = DateTime.Time(DateTime.Now - DateTime.TicksPerHour * TZOffset)
B4X:Public Sub GetTimeZoneOffset As Int Dim s, d As String Dim l As Long s = DateTime.DateFormat DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss" l = DateTime.Now d = DateTime.Date(l) & " GMT" DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss z" Dim res As Int res = -Round((l - DateTime.DateParse(d))/3600000) DateTime.DateFormat = s Return res End Sub
DateTime.SetTimeZone(0) 'only need to set it once so the process is now based on UTC timezone.
DateTime.DateFormat = "MM/dd/yyyy HH:mm:ss z"
Dim ticks As Long = DateTime.DateParse("03/07/2015 11:11:44" & " EST")
Log(DateTime.Date(ticks))
Just curious, is there any reason you use DateTime.TicksPerHour in one case and 3600000 in the other? Some hidden trap I can't see?This will give you the GMT time for any local time.
B4X:lblUTCTime.Text = DateTime.Time(DateTime.Now - DateTime.TicksPerHour * TZOffset)
B4X:(snip) res = -Round((l - DateTime.DateParse(d))/3600000) (snip)