Bopha
Bopha

Reputation: 3416

How to get GPS Time on Windows Mobile 6?

How can I get the time that is not based on my PC time? I use the code below to get time and it works, but when I change my computer time, the time is no longer correct, so is there a way that I can get the actual real time but not from PC time? Maybe GPS time?

    private void btn_DateTime_Click(object sender, EventArgs e)
    {
        DateTime dateTime = DateTime.Now;
        label_localTime.Text = dateTime.ToString();
        DateTime utcNow = DateTime.UtcNow;
        label_utc.Text = utcNow.ToString();


        TimeZone timeZone = TimeZone.CurrentTimeZone;
        if (timeZone.IsDaylightSavingTime(dateTime) == true)
        {
            label_dayLightSaving.Text = "YES";
            label_timeZone.Text = timeZone.GetUtcOffset(dateTime).ToString();
        }
        else
        {
            label_dayLightSaving.Text = "NO";
            label_timeZone.Text = "N//A";
        }                                  
    }

EDIT: Target device is running on WM6 and it has GPS hardware.

thanks.

Upvotes: 0

Views: 2323

Answers (5)

kenny
kenny

Reputation: 22334

If you have access to the GPS serial stream, one of the sentences has GMT/UTC time.

UPDATE: the $GPRMC sentence is the one. http://www.codepedia.com/1/The+GPRMC+Sentence

$GPRMC,UTC,POS_STAT,LAT,LAT_REF,LON,LON_REF,SPD,HDG,DATE,MAG_VAR,MAG_REF*CS

Upvotes: 0

Simeon Pilgrim
Simeon Pilgrim

Reputation: 25928

There are also Win32 API's to get uncorrected CPU time, which you have to localise your self.

When have an embedded GPS system running on Win32 platform, where we get GPS time and correct the local PC time while we are running. So for logging we just use local Windows time, but for timers we use the non-correct CPU time, to avoid timers running short or long when the system time is altered.

Upvotes: 0

David Basarab
David Basarab

Reputation: 73301

Since DateTime is based off of your CPU clock and your computer internal clock, there is no way you can get the DateTime not based on your CPU or computer time.

The best way would be to find a webservice to call that will give you, for example, the Navy Master Clock.

I don't know if there is a web service but you could get it form the site.

Upvotes: 0

Michael Petrotta
Michael Petrotta

Reputation: 60902

It sounds like you're looking for a network time server. Unless you have local hardware (GPS receiver, atomic time radio) to support other methods, network time is your best bet.

The Network Time Protocol (NTP) is a protocol for synchronizing the clocks of computer systems over packet-switched, variable-latency data networks.

Here's a client implementation using C#; it might help.

Upvotes: 7

Sinan Ünür
Sinan Ünür

Reputation: 118128

You could use ntp but it takes time to access a time source that is not on the computer running the program and accessing Tier 1 or Tier 2 servers too many times in a given time period is probably frowned upon.

Upvotes: 1

Related Questions