Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
how to get time in c++?
Results 1 to 5 of 5

Thread: how to get time in c++?

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    how to get time in c++?

    im working on my restarter for an ot, and i wonder how to get the time?
    currently i just call CMD and get output of "echo %time%"
    i supose that takes more cpu than *it cud have*

    any1 know how to get the current time in c++?

    Code:
    // Silent Restarter v1.1 by Yurez
    // edited by Hans Henrik.
    #include <windows.h>
    #include <iostream>
    int i = 0;
    int main(int argc, char *argv[])
    {
        if (argc != 2)
        {
        std::cout << "your supose to drop an exe here!" << std::endl;
            return 1;
        }
    
        STARTUPINFO si;
        PROCESS_INFORMATION pi;
    
        GetStartupInfo(&si);
        SetErrorMode(SEM_NOGPFAULTERRORBOX);
    
        while (true)
        {
            CreateProcess(argv[1], NULL, NULL, NULL, false,
                    HIGH_PRIORITY_CLASS, NULL, NULL, &si, &pi);
            if(i > 0)
            {
            std::cout << "restarted (or crashed) at: ";
            system("echo %time%"); // yeah.. know system aint the best way to go, ill better find out how to get system time c++-wise later :p
            std::cout << "(happend " << i << (i != 1? " times" : " time") << ")" << std::endl;
            }
            i += 1;
            WaitForSingleObject(pi.hProcess, INFINITE);
        }
    
        return 0;
    }

  2. #2
    Senior Member
    Join Date
    Jun 2007
    Posts
    247

    how to get time in c++?

    youll have to go through the windows api. under linux we have gettimeofday (); i dont know how to do it under windows, but go search the msdn

  3. #3
    Senior Member
    Join Date
    Aug 2007
    Posts
    115

    how to get time in c++?

    OTServ code:
    Code:
    void formatDate(time_t time, char* buffer)
    {
    	const tm* tms = localtime(&time);
    	if(tms){
    		sprintf(buffer, "%02d/%02d/%04d  %02d:%02d:%02d", tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900,
    			tms->tm_hour, tms->tm_min, tms->tm_sec);
    	}
    	else{
    		sprintf(buffer, "UNIX Time : %d", (int)time);
    	}
    }
    Using:
    Code:
    char date[21];
    formatDate(time(NULL), date);
    or:
    Code:
    formatDate(time(NULL), &date);

  4. #4
    Junior Member
    Join Date
    Mar 2007
    Posts
    24

    how to get time in c++?

    using time.h i guess..

    thanks!

  5. #5
    Senior Member
    Join Date
    Aug 2007
    Posts
    115

    how to get time in c++?

    You're welcome

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •