Thread: Date/Time confusion?

  1. #1
    the Wizard
    Join Date
    Aug 2004
    Posts
    109

    Unhappy Date/Time confusion?

    Hi,

    Need som help with a Date/Time problem.
    I've read page up and page down about different ways to determine the date and time in a function. But I get very confused because which way should I use? Which one can you recommand for me to use?

    I need to determine the time and date. So I can write it to a file with some other stuff i need to remember.

    The file creation and inputting is no problem though.

    Thx in advance.
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Here's a simple example.
    Code:
    #include <ctime>
    #include <iostream>
    using namespace std;
    
    int main()
    {
       time_t now = time(NULL);
       tm *t = localtime(&now);
       cout << t->tm_mon+1 << endl;
       cout << t->tm_mday << endl;
       cout << t->tm_year+1900 << endl;
       cout << t->tm_hour << endl;
       cout << t->tm_min << endl;
       cout << t->tm_sec << endl;
    
       return 0;
    }

  3. #3
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    What's the return type? Int?
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile Date/Time?
    By kinghajj in forum C# Programming
    Replies: 2
    Last Post: 10-31-2007, 09:46 AM
  2. for loop confusion
    By Enges in forum C++ Programming
    Replies: 6
    Last Post: 04-26-2006, 08:21 AM
  3. Server-net newbie confusion
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 04-28-2005, 02:08 AM
  4. confusion with increment and decrement operators
    By cBegginer in forum C Programming
    Replies: 6
    Last Post: 03-19-2005, 03:45 PM
  5. Help modifying date/time
    By bperov in forum C Programming
    Replies: 0
    Last Post: 06-06-2002, 08:50 AM