From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/chrono%2Fmktime.html | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 devdocs/c/chrono%2Fmktime.html (limited to 'devdocs/c/chrono%2Fmktime.html') diff --git a/devdocs/c/chrono%2Fmktime.html b/devdocs/c/chrono%2Fmktime.html new file mode 100644 index 00000000..d4a34bc9 --- /dev/null +++ b/devdocs/c/chrono%2Fmktime.html @@ -0,0 +1,46 @@ +

mktime

Defined in header <time.h>
time_t mktime( struct tm *arg );
+

Renormalizes local calendar time expressed as a struct tm object and also converts it to time since epoch as a time_t object. arg->tm_wday and arg->tm_yday are ignored. The values in arg are not checked for being out of range.

+

A negative value of arg->tm_isdst causes mktime to attempt to determine if Daylight Saving Time was in effect in the specified time.

+

If the conversion to time_t is successful, the arg object is modified. All fields of arg are updated to fit their proper ranges. arg->tm_wday and arg->tm_yday are recalculated using information available in other fields.

+

Parameters

+ +
arg - pointer to a tm object specifying local calendar time to convert

Return value

time since epoch as a time_t object on success, or -1 if arg cannot be represented as a time_t object (POSIX also requires EOVERFLOW to be stored in errno in this case).

+

Notes

If the struct tm object was obtained from POSIX strptime or equivalent function, the value of tm_isdst is indeterminate, and needs to be set explicitly before calling mktime.

+

Example

#define _POSIX_C_SOURCE 200112L // for setenv on gcc
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+ 
+int main(void)
+{
+    setenv("TZ", "/usr/share/zoneinfo/America/New_York", 1); // POSIX-specific
+ 
+    struct tm tm = *localtime(&(time_t){time(NULL)});
+    printf("Today is           %s", asctime(&tm));
+    printf("(DST is %s)\n", tm.tm_isdst ? "in effect" : "not in effect");
+    tm.tm_mon -= 100;  // tm_mon is now outside its normal range
+    mktime(&tm);       // tm_isdst is not set to -1; today's DST status is used
+    printf("100 months ago was %s", asctime(&tm));
+    printf("(DST was %s)\n", tm.tm_isdst ? "in effect" : "not in effect");
+}

Possible output:

+
Today is           Fri Apr 22 11:53:36 2016
+(DST is in effect)
+100 months ago was Sat Dec 22 10:53:36 2007
+(DST was not in effect)

References

See also

+ +
+
(C23)(C11)
converts time since epoch to calendar time expressed as local time
(function)
C++ documentation for mktime
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/chrono/mktime +

+
-- cgit v1.2.3