Last active
August 29, 2015 14:24
-
-
Save wakita/374807ef7a01e25d96ca to your computer and use it in GitHub Desktop.
閏秒にあわせて作成しました。100ミリ秒ごとにミリ秒単位で時刻を表示し続けます。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
while sleep 1 | |
do | |
ntpq -c rv; echo | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: ptime | |
ptime.o: ptime.c | |
ptime: ptime.o | |
clang++ -o $@ $^ | |
clean: | |
rm -f ptime ptime.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/time.h> | |
#include <time.h> | |
#include <unistd.h> | |
void ptime() { | |
struct timeval tv; | |
struct tm* ptm; | |
char time_string[40]; | |
long milliseconds; | |
/* Obtain the time of day, and convert it to a tm struct. */ | |
gettimeofday (&tv, NULL); | |
ptm = localtime (&tv.tv_sec); | |
/* Format the date and time, down to a single second. */ | |
strftime (time_string, sizeof (time_string), "%Y-%m-%d %H:%M:%S", ptm); | |
/* Compute milliseconds from microseconds. */ | |
milliseconds = tv.tv_usec / 1000; | |
/* Print the formatted time, in seconds, followed by a decimal point | |
* and the milliseconds. */ | |
printf ("%s.%03ld\n", time_string, milliseconds); | |
} | |
int main() { | |
while (1) { | |
ptime(); | |
usleep(100000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment