Question

I'm trying to set an alarm in windows phone using the following code

    private void btnSetAlarm_Click(object sender, RoutedEventArgs e)
    {
        date = (DateTime)datePicker.Value;
        time = (DateTime)timePicker.Value;
        beginTime = date + time.TimeOfDay;

        statusTextBlock.Text = beginTime.ToString(); //Display alarm time

        Alarm alarm = new Alarm("Wakeup4");
        alarm.Sound = new Uri("/Ringtones/ring.wav", UriKind.Relative);
        alarm.BeginTime = beginTime;

        ScheduledActionService.Add(alarm);
        MessageBox.Show("Alarm Created");
    }

Main problem is that when i set date as 2/17/2012 and time as 12:55 PM in the date and time picker respectively, alarm will get created but in the status bar it displays alarm set time as 2/18/2012 1:45:48 AM. Why is this happening? Is this because of time zone or what? By the way my system time is Indian standard time IST +5:30 and in the phone it is US time. I also changed phone time format to IST but it didn't work. Any suggestions?

Was it helpful?

Solution

I don't remember how the DatePicker works, but just to be sure you should use the 'Date' property to remove the time part of the DateTime result: beginTime = date.Date + time.TimeOfDay

OTHER TIPS

MSDN says that the time value should be in the device’s local time. Make sure that you don't have UTC somewhere (check DateTime.Kind property).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top