In the CentOS release 5.10, the results of the command 'date -u' command 'date' faster than the result of 25 seconds.
Here is the result:
[a@MG11ZA1 b]$ lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0- ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.10 (Final)
Release: 5.10
Codename: Final
[a@MG11ZA1 b]$ uname -a
Linux MG11ZA1 2.6.18-371.el5 #1 SMP Tue Oct 1 08:35:08 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux
[a@MG11ZA1 b]$ date && date -u && /usr/sbin/hwclock --show
Fri Jun 26 17:47:42 CST 2015
Fri Jun 26 09:48:07 UTC 2015
Fri 26 Jun 2015 05:47:18 PM CST -0.235359 seconds
And the result of the following code is not right
#include <time.h>
#include <stdio.h>
int main(int argc, char** argv)
{
time_t now = time(NULL);
struct tm today;
localtime_r(&now, &today);
printf(
"seconds:%d\n"
"minutes:%d\n"
"hours:%d\n"
"day of the month:%d\n"
"month:%d\n"
"year:%d\n"
"day of the week:%d\n"
"day in the year:%d\n"
"daylight saving time:%d\n"
,today.tm_sec
,today.tm_min
,today.tm_hour
,today.tm_mday
,today.tm_mon
,today.tm_year
,today.tm_wday
,today.tm_yday
,today.tm_isdst);
time_t weekstart = now - today.tm_wday * 24*60*60;
printf("weekstart:%u\n", (unsigned int)weekstart);
struct tm start;
localtime_r(&weekstart,&start);
start.tm_hour = 0;
start.tm_min = 0;
start.tm_sec = 0;
unsigned int version = mktime(&start);
printf("version:%u\n", version);
return 0;
}
The result of above code is:
seconds:53
minutes:54
hours:17
day of the month:26
month:5
year:115
day of the week:5
day in the year:176
daylight saving time:0
weekstart:1434880518
version:1434816025
The version should be 1434816000 not 1434816025, (now is 2015-06-26).
Thanks for any person to answer
At a guess, your timezone is
right/PRC
, which is a timezone that is explicitly adjusted for leap seconds. You can see the difference here:This is
right/PRC
, which does not apply the (current) 25 seconds to the time being reported:This is
PRC
, which has applied the (current) 25 seconds to the time being reported:This is
UTC
, which is the same timezone as is reported bydate -u
:Finally there is
right/UTC
, which is the time without the (current) 25 second adjustment:You should not really be using the
right/
timezones for general use - they do not match the reported time for most producers/consumers of time.