function
<ctime>

# time

`time_t time (time_t* timer);`
Get current time
Get the current calendar time as a value of type time_t.

The function returns this value, and if the argument is not a null pointer, it also sets this value to the object pointed by timer.

The value returned generally represents the number of seconds since 00:00 hours, Jan 1, 1970 UTC (i.e., the current unix timestamp). Although libraries may use a different representation of time: Portable programs should not use the value returned by this function directly, but always rely on calls to other elements of the standard library to translate them to portable types (such as localtime, gmtime or difftime).

### Parameters

timer
Pointer to an object of type time_t, where the time value is stored.
Alternatively, this parameter can be a null pointer, in which case the parameter is not used (the function still returns a value of type time_t with the result).

### Return Value

The current calendar time as a time_t object.

If the argument is not a null pointer, the return value is the same as the one stored in the location pointed by argument timer.

If the function could not retrieve the calendar time, it returns a value of `-1`.

time_t is an alias of a fundamental arithmetic type capable of representing times.

### Example

 ``123456789101112131415161718192021`` ``````/* time example */ #include /* printf */ #include /* time_t, struct tm, difftime, time, mktime */ int main () { time_t timer; struct tm y2k = {0}; double seconds; y2k.tm_hour = 0; y2k.tm_min = 0; y2k.tm_sec = 0; y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1; time(&timer); /* get current time; same as: timer = time(NULL) */ seconds = difftime(timer,mktime(&y2k)); printf ("%.f seconds since January 1, 2000 in the current timezone", seconds); return 0; }``````

Possible output:
 ```414086872 seconds since January 1, 2000 in the current timezone ```

### Data races

The object pointed by timer is modified (if not null).

### Exceptions (C++)

No-throw guarantee: this function never throws exceptions.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5546106,"math_prob":0.99301076,"size":537,"snap":"2023-40-2023-50","text_gpt3_token_len":206,"char_repetition_ratio":0.15196998,"word_repetition_ratio":0.0,"special_character_ratio":0.46554935,"punctuation_ratio":0.25,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.963348,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-11-30T04:41:58Z\",\"WARC-Record-ID\":\"<urn:uuid:1f8c318e-7030-4cf6-af82-468b78d63b45>\",\"Content-Length\":\"28221\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:380eb594-42db-4d6e-b8b2-aa73802abadd>\",\"WARC-Concurrent-To\":\"<urn:uuid:55f25c1e-52b2-4343-ab61-b999f4ada22f>\",\"WARC-IP-Address\":\"54.39.7.252\",\"WARC-Target-URI\":\"https://cplusplus.com/reference/ctime/time/\",\"WARC-Payload-Digest\":\"sha1:AXEKZQ4BYYECAOVKVESEV2CC7B4QGIU4\",\"WARC-Block-Digest\":\"sha1:DJJ45PXUY2NHMNNYMOLIH4LNBGTDJZ3X\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100164.87_warc_CC-MAIN-20231130031610-20231130061610-00582.warc.gz\"}"}