Format specifier to print time(0) in C

前端 未结 5 1625
南方客
南方客 2021-01-22 06:18

We can declare a variable to hold the current time from the system using:

time_t now = time(0);

time(0) can also be use in genera

5条回答
  •  鱼传尺愫
    2021-01-22 07:11

    looking into the header file(s) for the time function, you will see that the parameter can be one of two things NULL or address of time_t variable.

    The time() function results for both the parameter and the returned value is the elapsed time, in seconds, since the epoch (currently Jan 1, 1970 00:00 am UTC.) The sizing of the value (on older systems) was 4 bytes (32bits). with recent RTC (RealTimeClock) hardware available, the value 'may' be 8 bytes (64bits) . in any case the value in is seconds since the epoch.

    The 4 byte time values will overflow in 2038, so efforts are being made to either 1) make the time value a larger size or 2) shift the epoch time forward to Jan 1 2000 00:00 am. ( a temporary fix when using older hardware )

    the changing of the time values to 8 bytes is the current preferred method.

    here is a specific quote from google:

    "At 03:14:08 UTC on 19 January 2038, 32-bit versions of the Unix time stamp will cease to work" to paraphase the rest of the quote: the 32 bit value will overflow.

    The functions that handle time, like localtime() strtotime(). etc and the related structs, like tm, are setup to use what ever the system they are running on is returning from the time() function.

    All the processing of the value from the time function should be done using the available functions rather than handling the raw value.

提交回复
热议问题