2012-08-26 wcdj
由UNIX时间戳转换为系统时间
date -d'1970-01-01 UTC 2147483647 seconds' +"%Y-%m-%d %T %z"
2038-01-19 11:14:07 +0800
date -d'1970-01-01 UTC 2147483648 seconds' +"%Y-%m-%d %T %z"
date: invalid date "1970-01-01 UTC 2147483648 seconds"
date -d'1970-01-01 UTC 0 seconds' +"%Y-%m-%d %T"
1970-01-01 08:00:00 +0800
显示当前的UNIX时间戳
date +%s
Unix时间与系统时间之间的转换
http://shijianchuo.911cha.com/
/*
* 2012-08-26 wcdj
* 使用Gauss算法解决UNIX时间问题
* 将UNIX时间2038-01-19 03:14:08
* 支持扩大到2106-02-07 06:28:16
*/
#include <stdio.h>
#include <string.h>
#include <time.h> // struct tm, mktime
#include <sys/time.h> // gettimeofday
#define MAX_TIME_DIFF (24*60*60)
#define SECS_PER_HOUR (60 * 60)
#define SECS_PER_DAY (SECS_PER_HOUR * 24)
// calc microseconds
long long get_time_of_day()
{
struct timeval tv;
if (gettimeofday(&tv, NULL) == 0)
{
return tv.tv_sec * 1000000ULL + tv.tv_usec;
}
else
{
return 0;
}
}
static long _timezone = MAX_TIME_DIFF+1;
/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
* Assumes input in normal date format, i.e. 1980-12-31 23:59:59
* => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
*
* [For the Julian calendar (which wa