Day, Time

Was making a project for the 12th Standard and I actually was making a ticket booking portal kind of thing so I wanted to extract the current day (i.e. Sunday, Monday,etc.), future day so that the ticket prices could be changed accordingly and also for the display. Display is not a problem C++ Help itself there are example programs but could not find a method where I could extract the different elements of current time separately. Tried many things but structure pointers were causing a lot of problem. Please post a solution.
Thank You
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <ctime>

void foo()
{
    // get current time: http://cplusplus.com/reference/clibrary/ctime/time/
    std::time_t now = std::time(0) ;

    // convert it to the local time: http://cplusplus.com/reference/clibrary/ctime/localtime/
    const std::tm* ptm = std::localtime(&now) ;

    // members of the structure have the information you need 
    // http://cplusplus.com/reference/clibrary/ctime/tm/
    std::cout << ptm->tm_hour << ' ' << ptm->tm_wday << '\n' ;
}

Thank you will try it out! :D
Topic archived. No new replies allowed.