シェルスクリプトでは、現地時間が必要なときはいつでも次のようにします
date +%s
コマンドラインから、現在の日付と時刻を「1343221713」の形式で返します
Cで同じ結果を達成する方法があるかどうか疑問に思っています
Cでtime.hライブラリを使用する
例:
#include <stdio.h>
#include <time.h>
int main()
{
/* Obtain current time as seconds elapsed since the Epoch. */
time_t clock = time(NULL);
/* Convert to local time format and print to stdout. */
printf("Current time is %s", ctime(&clock));
return 0;
}
その他の例を参照してください:http: //en.wikipedia.org/wiki/C_date_and_time_functions
で宣言されているよりも柔軟time(3)
ですgettimeofday(3)
sys/time.h
#include <sys/time.h>
#include <stdio.h>
int main(void)
{
struct timeval tv = {0};
gettimeofday(&tv, NULL);
printf("seconds since epoch %ld, microseconds %ld\n", tv.tv_sec, tv.tv_usec);
return 0;
}