C Standard Libraries C++

ctime()

Declaration

char* ctime(const time_t* kqpTime);

Description

This function converts the time_t variable that "kqpTime" points to into a null-terminated character string that describes the local time. The data type, time_t, is used to get the time from the time function, which returns the number of seconds since midnight January 1, 1970.

Example

#include <iostream>
#include <ctime>

int main() {
    using namespace std;

    time_t qTime;
    // Get the number of seconds since midnight Jan. 1, 1970
    time(&qTime);
    // Convert the seconds to a string which describes the local time
    char* cpLocalTime = ctime(&qTime);
    cout << "The local time is " << cpLocalTime << endl;

    return 0;
}

Output

ctime() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.