algorithm/function that returns date?

This is a discussion on algorithm/function that returns date? within the C++ Programming forums, part of the General Programming Boards category; i've asked around and looked (peeked) in the standard library files but haven't found anything that returns the time to ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    28

    algorithm/function that returns date?

    i've asked around and looked (peeked) in the standard library files but haven't found anything that returns the time to a program. I need this for a game of minesweeper im writing, for which i need to keep a "stats" file with the name of the player, the date of the game and how long the player took to finish the game. any help will be greatly appreciated 8)

    thanks in advance ;D
    the early bird gets the worm but the second mouse gets the cheese

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    have you tried 'peeking' into the <ctime> header for the time() function or the strftime() function for the current time... or the clock() function to time the game?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    28
    yeah i have a class which calculates the timer for the game, what i needed was something to get the date ;/

    gonna go try those that you gave me, thanks guys : ]
    the early bird gets the worm but the second mouse gets the cheese

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    The locale class contains time input and output facets too. For locale-dependent time representation as strings.

    And the boost libraries contain a date/time library.
    www.boost.org
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    28
    agh i tried both - no avail ;/
    how do you manipulate the ones in time.h for them to return the date to you? i tried a couple things, got it to compile but then nothing happened :/

    the boost.org page offers some interesting functions but nothing that actually gives me the current date - it just offers classes which store dates and manipulates them to do a couple of things.

    sorry to keep bothering, and thanks again
    the early bird gets the worm but the second mouse gets the cheese

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    28
    still stumped.
    Code:
    #include <time.h>   
    char *asctime( const struct tm *ptr );
    trying to use that but dont know how ;/
    help please
    the early bird gets the worm but the second mouse gets the cheese

  8. #8
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  9. #9
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Maybe this helps:
    Code:
    #include <cstdio>
    #include <iostream>
    #include <ctime>
    using namespace std;
    int main ()
    {
      time_t rawtime;
      struct tm * timeinfo;
      time ( &rawtime );
      timeinfo = localtime ( &rawtime );
      
      int day = timeinfo->tm_mday;
      int month = timeinfo->tm_mon + 1;
      int year = timeinfo-> tm_year + 1900;
      
      cout << "day = " << day << endl;
      cout << "month = " << month << endl;
      cout << "year = " << year << endl;
      
      system("PAUSE");
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21