std::time - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::time

From cppreference.com
< cpp‎ | chrono‎ | c

Defined in header `<ctime>` |  |
std::time_t time( std::time_t *time ); |  |

Returns the current calendar time encoded as a std::time_t object.

### [edit] Parameters

time | - | pointer to a std::time_t object to store the time in or NULL

### [edit] Return value

Current calendar time encoded as std::time_t object on success, (std::time_t)(-1) on error. If the argument is not NULL, the return value is also set to the object pointed by `time`.

### [edit] Notes

The encoding of calendar time in std::time_t is unspecified, but most systems conform to POSIX specification and return a value of integral type holding the number of seconds since the Epoch. Implementations in which std::time_t is a 32-bit signed integer (many historical implementations) fail in the year 2038.

### [edit] Example

Run this code

    #include <ctime>
    #include <iostream>

    int main()
    {
        std::time_t result = std::time(NULL);
        std::cout << std::asctime(std::localtime(&result))
                  << result << " seconds since the Epoch\n";
    }

Output:

    Wed Sep 21 10:27:52 2011
    1316615272 seconds since the Epoch

### [edit] See also

localtime | converts time since epoch to calendar time expressed as local time (function) [edit]
gmtime | converts time since epoch to calendar time expressed as Universal Coordinated Time (function) [edit]
system_clock (C++11) | wall clock time from the system-wide realtime clock (class) [edit]
C documentation for time

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/chrono/c/time&oldid=67436"