Time and Timezone functions in SDF 2.0

SDF 2.0 continues to have functionality for working with the time and time zones for devices.  The differences from SDF 1.x are a namespace change, a classname change (don’t believe the beta docs or the beta, these have changed since that drop), and under the hood a lot more internal checks are going on to head off errors and to provide correct device support.  Basically this one has been pretty heavily tested across a broad range of devices.


Some quick highlights:


Getting and Displaying a List of Time Zones


using OpenNETCF.WindowsCE;

// get and display all available zones
TimeZoneCollection tzc = new TimeZoneCollection();
tzc.Initialize();

foreach (TimeZoneInformation tzi in tzc)
{
    lstZones.Items.Add(tzi);
}


Displaying the Currently Set Time Zone


using OpenNETCF.WindowsCE;

// get and display the currrent zone

TimeZoneInformation currentTz = new TimeZoneInformation();
DateTimeHelper.GetTimeZoneInformation(ref currentTz);
lblCurrentZone.Text = currentTz.StandardName;


Setting the Current Time Zone (from the Listing above)


using OpenNETCF.WindowsCE;

if
(lstZones.SelectedItem != null)
{
    TimeZoneInformation tzi = (TimeZoneInformation)lstZones.SelectedItem;
    DateTimeHelper.SetTimeZoneInformation(tzi);

    // this verifies that the time zone did indeed get changed
    TimeZoneInformation tz = new TimeZoneInformation(
        (byte[])Registry.LocalMachine.OpenSubKey(“Time”).GetValue(
            “TimeZoneInformation”));
    MessageBox.Show(“Current Timezone in Registry is:rn” 
        + tz.StandardName, “Verified”);
}


Displaying the Current Time (without DateTime.Now)


using OpenNETCF.WindowsCE;

DateTime dt = DateTimeHelper.SystemTime;

txtHour.Text = dt.Hour.ToString();
txtMinute.Text = string.Format(“{0:00}”, dt.Minute);
txtSecond.Text = string.Format(“{0:00}”, dt.Second);


Setting The Current System Time (Local Time is Analogous)


using OpenNETCF.WindowsCE;

// get the current time so we can copy the date part

DateTime dt = DateTimeHelper.SystemTime;

DateTimeHelper.SystemTime = new DateTime(dt.Year, dt.Month, dt.Day,
    int.Parse(txtHour.Text), int.Parse(txtMinute.Text), int.Parse(txtSecond.Text));


 

7 thoughts on “Time and Timezone functions in SDF 2.0”

  1. I’m not seeing any support for Daylight Savings – all the daylight savings times are 0 – is there something lacking in the SDF support? or is there possibly a missing config file on my device?

    Thanks

    Like

  2. Hi All,

    While using: DateTimeHelper.SetTimeZoneInformation(tzi);

    If I try to set "Eastern Time" as in the normal GMT-5 Eastern Standard/Daylight. The control pannel shows Indiana Time both are -300 minutes but have different standard / daylight rules.

    The same problem occurs with "Central Time" also, it shows "Canadian Central Time" in control panel.

    Regards,
    Mayank Parmar
    mayank.parmar@clariontechnologies.co.in
    +91 9727748789

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s