Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::time

      From cppreference.com
      <cpp‎ |chrono‎ |c
       
       
      Date and time library
       
       
      Defined in header<ctime>

      Returns the current calendar time encoded as astd::time_t object, and also stores it in the object pointed to byarg, unlessarg is a null pointer.

      Contents

      [edit]Parameters

      arg - pointer to astd::time_t object to store the time, or a null pointer

      [edit]Return value

      Current calendar time encoded asstd::time_t object on success,(std::time_t)(-1) on error. Ifarg is not null, the return value is also stored in the object pointed to byarg.

      [edit]Notes

      The encoding of calendar time instd::time_t is unspecified, but most systems conform to thePOSIX specification and return a value of integral type holding 86400 times the number of calendar days sincethe Epoch plus the number of seconds that have passed since the last midnight UTC. Most notably, POSIX time does not (and can not) take leap seconds into account, so that this integral value is not equal to the number ofS.I. seconds that have passed since the epoch, but rather is reduced with the number of leap seconds that have occurred since the epoch. Implementations in whichstd::time_t is a 32-bit signed integer (many historical implementations) fail in the year2038.

      [edit]Example

      Run this code
      #include <ctime>#include <iostream> int main(){std::time_t result= std::time(nullptr);std::cout<<std::asctime(std::localtime(&result))<< result<<" seconds since the Epoch\n";}

      Possible output:

      Wed Sep 21 10:27:52 20111316615272 seconds since the Epoch

      [edit]See also

      returns the calendar time in seconds and nanoseconds based on a given time base
      (function)[edit]
      converts time since epoch to calendar time expressed as local time
      (function)[edit]
      converts time since epoch to calendar time expressed as Universal Coordinated Time
      (function)[edit]
      wall clock time from the system-wide realtime clock
      (class)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/c/time&oldid=180262"

      [8]ページ先頭

      ©2009-2025 Movatter.jp