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

2

There are 2 answers

0
Anya Shenanigans On BEST 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:

env TZ=right/PRC date
Fri Jun 26 19:13:18 CST 2015

This is PRC, which has applied the (current) 25 seconds to the time being reported:

env TZ=PRC date
Fri Jun 26 19:13:43 CST 2015

This is UTC, which is the same timezone as is reported by date -u:

env TZ=UTC date
Fri Jun 26 11:13:43 UTC 2015

Finally there is right/UTC, which is the time without the (current) 25 second adjustment:

env TZ=right/UTC date
Fri Jun 26 11:13:18 UTC 2015

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.

1
Axel On

I am not sure I understand your question correctly, but I think the 25 seconds you see is the difference between "normal" and "UTC" time because of the leap seconds. Next month it should be 26 seconds btw.

Quote from Wikipedia:

Since this system of correction was implemented in 1972, 25 such leap seconds have been inserted.