Ask Your Question
4

How can I obtain a Unix timestamp using C++?

asked 2023-05-29 07:31:22 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-29 08:00:01 +0000

scrum gravatar image

You can obtain a Unix timestamp using C++ by using the standard library function time and then casting the result to a time_t data type. Here's an example:

#include <iostream>
#include <ctime>

int main() {
    std::time_t result = std::time(nullptr);
    std::cout << "Unix timestamp: " << result << std::endl;
    return 0;
}

This code will output the current Unix timestamp in seconds since the Unix epoch (January 1, 1970).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-29 07:31:22 +0000

Seen: 15 times

Last updated: May 29 '23