-1

I'm learning C++. While doing a clock program I was wondering how do you get the current system time?

W.K.S
  • 9,787
  • 15
  • 75
  • 122
Mayur
  • 49
  • 1
  • 6
  • 9
    It's courageous of you to learn c++ at such a young age and I wsih you all the best but this question has been answered several times before and will likely by closed. Please check out this answer: http://stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c – W.K.S Apr 09 '16 at 15:22
  • 1
    @W.K.S how would you know his age? – JSQuareD Apr 09 '16 at 15:32
  • 3
    @Mayur: the linked question is quite old, scroll down to see answers for the post C++11 era. – JSQuareD Apr 09 '16 at 15:36
  • 2
    @JSQuareD check the history/edits of the question – default Apr 09 '16 at 15:42

2 Answers2

3

C++ provides the std::chrono library to deal with date and time values.

You can get the current system time using std::chrono::system_clock::now():

auto start = std::chrono::system_clock::now();

The linked reference contains a more complete example.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
1

std C libraries provide time(). This is seconds from the epoch and can be converted to date and H:M:S using standard C functions. Boost also has a time/date library that you can check.

time_t  timev;
time(&timev);

Please make sure you are googling/researching before you ask questions..

Jay Mason
  • 446
  • 3
  • 17