# how to convert GPS UTC time to milli-second of the week?

• ### Question

• Good morning,

Can someone tell me how to convert hhmmss.ss (UTC) to milli-second of the week?

e.g. 022256.00 (UTC)

Thanks for any assistance.

Monday, August 6, 2007 2:30 PM

• I would convert the parsed time to a DateTime object in C#.  Then programtically I would create a new DateTime object that referred to the beginning of the week (0000 Sunday).

Then maybe you can do.

TimeSpan tsDifference = dtParsedTime.Subtract(dtWeekStart);

int ms = tsDifference.Milliseconds;

What do you think?
Tuesday, August 7, 2007 7:53 PM
•

> int ms = tsDifference.Milliseconds;

Actually that should be:

Code Snippet

double ms = tsDifference.TotalMilliseconds;

Tuesday, August 7, 2007 8:37 PM

### All replies

• Assuming you consider Sunday that start of the week, you can do something like this

Code Snippet

DateTime weekStart = DateTime.Now.ToUniversalTime();

while (weekStart.DayOfWeek != DayOfWeek.Sunday)
{
}

TimeSpan ts = DateTime.Now.ToUniversalTime().Subtract(weekStart);
MessageBox.Show(ts.TotalMilliseconds.ToString());

Monday, August 6, 2007 3:16 PM

This is what I have, where "time" is the UTC that I am extracting:

if (data.h.ContainsKey("time"))

word.writeVal(0, 30, data.h["time"], "uint");

how can I modify your code to fit in here.  Thanks

Monday, August 6, 2007 3:37 PM
•

Hello,

Not sure if C# has the library to handle this or need to create a function.

I am parsing UTC time/date from sentence \$GPRMC.  Then I need to CONVERT to milli-seconds of the week since the beginning of the week (0000 Sunday GMT).

for example:

\$GPRMC,040302.00,A,3209.992,N,11052.530,W,0.00,93.70, 070807,11.30,E*7C

I would extract 040302.00 and 070907 and converted to milliseconds of the week (0000 SUnday GMT).

Tuesday August 07, 2007 04:03:02.00 AM UTC  would equal to: 187,382,000 milliseconds

Any ideas/suggestion would be appreciated.

Tuesday, August 7, 2007 6:30 PM
• I would convert the parsed time to a DateTime object in C#.  Then programtically I would create a new DateTime object that referred to the beginning of the week (0000 Sunday).

Then maybe you can do.

TimeSpan tsDifference = dtParsedTime.Subtract(dtWeekStart);

int ms = tsDifference.Milliseconds;

What do you think?
Tuesday, August 7, 2007 7:53 PM
•

> int ms = tsDifference.Milliseconds;

Actually that should be:

Code Snippet

double ms = tsDifference.TotalMilliseconds;

Tuesday, August 7, 2007 8:37 PM
• yeah... my bad.. but yeah my idea is still how you should go about it I think.
Tuesday, August 7, 2007 8:56 PM