Hi Theera,
let's try to figure out together the whole process.
1. Event location: Rome, Italy
2. Event Date: 2013-10-31
3. Event time: 10:00 local time in Rome
4. Check the timeanddate.com site to read the correct UTC offset; here we learn that for Rome in year 2013 DST ended on October 27th, 3 A.M. so the offset went from +2 to +1 at that moment and will stay so until 2014 March 30th, 2 A.M. local time.
This means that for our Event date (
4 days after offset change) the right UTC offset should be
+1.
5. So now we can set our variable EventDate=DateUtils.SetDateAndTime2(2013,10,31,10,0,0,
1). The effect of this function is to compute the given event date/time as if it was shifted to Greenwich (or any other UTC 0 zone), making it comparable with result from function Now().
6. Reading dt_now= DateTime.Now it gives us current date/time (again, as it is referring to UTC 0)
7. Finally, DateUtils.PeriodBetween(EventDate, dt_now) computes the difference between those two date/time moments and since they are both expressed as UTC0-based this comparision works and is right.
As an exercise on a real event, the following code shows how to start a countdown to next Olympic Games grand opening (arbitrarly set by me at 18:00, local time). What we know is the location (Rio de Janeiro, Brazil), the date (2016-08-05) and an arbitrary local time (I set it at 18:00).
From timeanddate.com site we learn that the offset at the time of the event will be UTC-3.
So we have:
Sub Globals
Dim EventDate AsLong = DateUtils.SetDateAndTime2(2016,8,5,18,0,0,-3) ' Olympics opening on August 5th 2016 18:00:00
Dim lblCountDown AsLabel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1")
dt_now= DateTime.now 'This exact moment, expressed as UTC 0 time
'remaining time before Event; both datetimes are expressed as UTC 0, so the difference should be correct
Dim CountDown As Period = DateUtils.PeriodBetween(EventDate, dt_now)
lblCountDown.Text = CountDown.Years & CountDown.Months & CountDown.Days & CountDown.Hours & CountDown.Minutes & CountDown.Seconds
Timer1.Initialize("Timer1", 1000) ' 1000 = 1 second
Timer1.Enabled = True
End Sub
Hope this will be of any help.
Umberto