Re: What does mktime return????

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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






Code :


#include <stdio.h>
#include <time.h>

main()
{
    struct tm time_str , time_str2;

    time_str.tm_sec = 59; //30 Nov 2019 23:59:59
    time_str.tm_min = 59;
    time_str.tm_hour = 23;
    time_str.tm_mday = 30;
    time_str.tm_mon = 11;
    time_str.tm_year = 119;
    time_str.tm_isdst = 0;
time_str2.tm_sec = 0; // 1 Dec 2019 00:00:00
    time_str2.tm_min = 0;
    time_str2.tm_hour = 0;
    time_str2.tm_mday = 1;
    time_str2.tm_mon = 12;
    time_str2.tm_year = 119;
    time_str2.tm_isdst = 0;

    printf( "%d %d %d\n" , mktime( &time_str ) , mktime( &time_str2 ) ,
	   mktime( &time_str ) - mktime( &time_str2 ) );

}







Pax, vel iniusta, utilior est quam iustissimum bellum.
     (free after Marcus Tullius Cicero (106 b.Chr.-46 b.Chr.)
      Epistularum ad Atticum 7.1.4.3)


                Touch not the cat bot a glove

------------------------------------------------------------------------------<
   Jouk Jansen
		
   joukj@xxxxxxxxxxxxxxxxxxxx

   Technische Universiteit Delft        tttttttttt  uu     uu  ddddddd
   Kavli Institute of Nanoscience       tttttttttt  uu     uu  dd    dd
   Nationaal centrum voor HREM              tt      uu     uu  dd     dd
   Lorentzweg 1                             tt      uu     uu  dd     dd
   2628 CJ Delft                            tt      uu     uu  dd     dd
   Nederland                                tt      uu     uu  dd    dd
   tel. 31-15-2782272                       tt       uuuuuuu   ddddddd

------------------------------------------------------------------------------<


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.


*Mark C. Allman, PMP, CSM*
Founder, See How You Ski, www.seehowyouski.com <http://www.seehowyouski.com>
Sr. Project Manager, Allman Professional Consulting, Inc., www.allmanpc.com <http://www.allmanpc.com>
617-947-4263, Twitter: @allmanpc

_______________________________________________
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



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux