Display date of server..

This is a discussion on Display date of server.. within the C++ Programming forums, part of the General Programming Boards category; I'm running a server, and I would like to display current date for my server... Why the following codes are ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    3

    Question Display date of server..

    I'm running a server, and I would like to display current date for my server...

    Why the following codes are incorrect? My compiler won't let me compile, as it refer I declared the the "server" variable wrongly..

    Code:
    			time_t now = time(NULL);
       			tm *t = localtime(&now);
    			struct date {
    				char day;
    				char month;
    				char year;
    			}
    			
    			date server;
    			server.day->tm_mday;
    			server.month->tm_mon+1;
    			server.year->tm_year+1900;
    			
    			cout << server;
    Anyone can point me what is wrong? Anyhelp wouldb e appreciated.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > struct date {
    > char day;
    > char month;
    > char year;
    > }
    >
    > date server;
    > server.day->tm_mday;
    > server.month->tm_mon+1;
    > server.year->tm_year+1900;
    >
    > cout << server;
    Try:
    Code:
    			time_t now = time(NULL);
       			tm *t = localtime(&now);
    			struct date {
    				int day;
    				int month;
    				int year;
    			}
    			
    			date server;
    			server.day = tm->tm_mday;
    			server.month = tm->tm_mon+1;
    			server.year = tm->tm_year+1900;
    			
    			cout << server.day << "/" << server.month << "/" << server.year << endl;
    Or:
    Code:
    			time_t now = time(NULL);
       			tm *t = localtime(&now);
    			char date[30];
    			if ( strftime(date, sizeof(date), "%x", t) != 0 )
    			   cout << date << endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. server client application - (i really need your help)
    By sarahnetworking in forum C Programming
    Replies: 3
    Last Post: 03-01-2008, 10:54 PM
  2. Date Last Modified
    By magic.mike in forum Windows Programming
    Replies: 5
    Last Post: 09-23-2005, 06:13 AM
  3. casting the system exstracted date into seperate ints
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-30-2005, 01:17 AM
  4. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  5. Web Server in Router Network...
    By Aidman in forum Tech Board
    Replies: 15
    Last Post: 01-17-2003, 10:24 PM

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