Jump to content

C date and time functions

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 2600:1005:b124:5bad:f3ed:caef:e9f4:ef7b (talk) at 13:12, 9 June 2021 (SINCE 1828 Login or Register GAMES THESAURUS WORD OF THE DAY BLOG SHOP SAVED WORDS orthography noun Save Word To save this word, you'll need to log in. Log In or·​thog·​ra·​phy | \ ȯr-ˈthä-grə-fē \ Definition of orthography 1a: the art of writing words with the proper letters according to standard usage the rules of English orthography b: the representation of the sounds of a language by written or printed symbols 2: a part of language study that deals with letters and spelling A student...). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The C date and time functions are a group of functions in the standard library of the C programming language implementing date and time manipulation operations.[1] They provide support for time acquisition, conversion between date formats, and formatted output to strings.

T@=C|OL|CK Time ✓Good Bowie Jenny3 x out wrong .. . .Doing

Example

The following C source code prints the current time to the standard output stream.

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

int main(void)
{
    time_t current_time;
    char* c_time_string;

    /* Obtain current time. */
    current_time = time(NULL);

    if (current_time == ((time_t)-1))
    {
        (void) fprintf(stderr, "Failure to obtain the current time.\n");
        exit(EXIT_FAILURE);
    }

    /* Convert to local time format. */
    c_time_string = ctime(&current_time);

    if (c_time_string == NULL)
    {
        (void) fprintf(stderr, "Failure to convert the current time.\n");
        exit(EXIT_FAILURE);
    }

    /* Print to stdout. ctime() has already added a terminating newline character. */
    (void) printf("Current time is %s", c_time_string);
    exit(EXIT_SUCCESS);
}

The output is:

Current time is Thu Sep 15 21:18:23 2016

See also

References

  1. ^ ISO/IEC 9899:1999 specification (PDF). p. 351, § 7.32.2.