On 18/12/2019 15:12, Mark C. Allman wrote:
On 12/18/19 9:17 AM, Jouk Jansen wrote:
Hi All,
I'm strugling with the C-function mktime. According to the man-pages it
returns "seconds since the Epoch". I tried to use this functions to get
differnces from two date-times , but was could not interpret the result.
When trying to get the diffrence between 30 Nov 2019 23:59:59 and 1
Dec 2019
00:00:00 (see code below) I expected to find 1 second difference but I
find:
1577746799 1577833200 -86401
As output of the sample program. (and not 1577833199 1577833200 -1)
How should I read "seconds since the Epoch"????
Is the output of mktime correct?
(I also tried 31 Nov and got the expected 1 second)
(should mktime not give an error for 31 Nov??)
Regards
Jouk
The month value range is 0 to 11, not 1 to 12. You're calculating
12/30/2019 at 23:59:59 to 01/01/2020 at 00:00:00, or 86401 seconds.
This is in accord with 'man mktime' but it's certainly a trap for the
unwary. Calendar days are treated normally, but not months. I wonder
how many space probes have strayed or contracts misfired...
Changing it now would cause yet more confusion.
John P
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx