Setting time with specific format string
I have looked at the man page and experimented with a few things, but I haven't been able to figure this out.
Can anyone tell me why this works: Code:
date -u +%T -s "21:25:26" Code:
date -u +%H%M%S -s "212526" This isn't a very serious issue, it is really just something I was playing around with and thought was odd. What I am trying to do is set the system time to the UTC time string that is returned from my GPS every second. For example, this command reads the NMEA output of the GPS, and returns the UTC time when it is reported (exactly once per second): Code:
root@T-Bird:/~# awk -F, '/\$GPGGA/ {print $2; exit}' /dev/rfcomm0 NOTE: I am aware this is not the proper way to do this, and like I said, this was more of a experiment than anything. The right way to get PPS accuracy on a Linux machine requires kernel patching and some userland utilities, but I wanted to see how close I could get doing it by hand. |
I've seen different formats and do not know how it works with timezone data.
date MMDDhhmm[[CC] YY] [.ss] CC = century YY = year ss = seconds http://www.oreillynet.com/linux/cmd/cmd.csp?path=d/date Post back on your results. |
The last example looks promising, assuming it works in UTC also:
Code:
Set the date to July 1 (0701), 4 a.m. (0400), 2005 (05): The man page for "date" seems to indicate that you can tailor your input the same way you can do for output: Code:
-d, --date=STRING |
With my Garmin 18 LVC the reference is the one-pulse-per-second output pulse immediately preceding the GPRMC sentence, or whichever sentence is first programed. You can determine the RS-232 transmission latency but it will difficult to determine latencies due to OS.
|
Well, this actually seems to get pretty close. It may actually be a little closer than my stratum 3 NTP server.
The script: Code:
#!/bin/sh Code:
root@T-Bird:/~# awk -F, '/\$GPGGA/ {print $2; exit}' /dev/rfcomm0 && date -u +%H%M%S.%N | cut -c 1-10 Interestingly, running that same command on my NTP server: Code:
root@Mainframe:/~# awk -F, '/\$GPGGA/ {print $2; exit}' /dev/rfcomm0 && date -u +%H%M%S.%N | cut -c 1-10 While this is a very rough experiment, I wonder what type of results I would get if I ran this script every 15 or 30 minutes on my NTP server rather than pulling time from a stratum 2 server. Perhaps I could even improve the execution speed of this script a bit, I am sure there is a better way to separate the UTC string into HHMM and SS, but I can't think of how. |
Would the + part be ignored, since that's for how the date is outputted, not inputted? Beyond that I never really figured out date for setting the date/time. But it does work if you input date and time in two separate commands
date -s "20090921" date -s "12:31:30.123" Although I typically just do an ntpdate time-b.nist.gov Unless I don't have an internet connection, where I have to do the previous date method. |
All times are GMT -5. The time now is 11:12 PM. |