C + + Acquisition time

Source: Internet
Author: User

C + + Acquisition time

Header file Chrono, namespace Std.

Now time
Std::chrono::system_clock::now () returns the current time of the system clock

Clock
Std::chrono::system_clock represents the current time of the system, is an unstable clock, and provides a function to convert a point in time to a value of time_t type
Std::chrono::steady_clock represents a stable clock, so-called stability refers to the call now (), whose value is always greater than 1 times.

Delay
Std::this_thread::sleep_for () and Std::this_thread::sleep_until ()
Std::this_thread::sleep_for (std::chrono::milliseconds (100)); Wait 100ms

1 #define_crt_secure_no_warnings2 3#include <iostream>4#include <string>5#include <sstream>6#include <iomanip>7#include <chrono>8 9STD::stringgettimestr ()Ten { OneStd::chrono::system_clock::time_point now =Std::chrono::system_clock::now (); Atime_t TT =std::chrono::system_clock::to_time_t (now); -     structTM LTM = {0}; -Localtime_s (&ltm, &TT); the Std::stringstream stm; -STM << Std::setfill ('0'); -STM << STD::SETW (4) << (Ltm.tm_year +1900) <<"-"; -STM << STD::SETW (2) << (Ltm.tm_mon +1) <<"-"; +STM << STD::SETW (2) << (Ltm.tm_mday) <<" "; -STM << STD::SETW (2) << (Ltm.tm_hour) <<"-"; +STM << STD::SETW (2) << (ltm.tm_min) <<"-"; ASTM << STD::SETW (2) <<(ltm.tm_sec); at  -     returnstm.str (); - } -  - voidMyTestvoid) - { inStd::cout <<"<<<<<<<<<<<<<<<<<<<<<<<<<"<<Std::endl; -  toStd::chrono::steady_clock::time_point Tbegin =Std::chrono::steady_clock::now (); +Std::cout << gettimestr (). C_STR () <<Std::endl; -Std::chrono::steady_clock::time_point tend =Std::chrono::steady_clock::now (); theStd::chrono::milliseconds used = Std::chrono::d uration_cast<std::chrono::milliseconds> (Tend-tbegin); *Std::cout << used.count () <<"Ms"<<Std::endl; $ Panax NotoginsengStd::cout <<"<<<<<<<<<<<<<<<<<<<<<<<<<"<<Std::endl; - } the  + intMainintargcChar* argv[],Char*envp[]) A { the mytest (); +  -System"Pause"); $     return 0; $}

Operation Result:

C + + Acquisition time

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.