gooderp18绿色标准版
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1427 lines
116KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="time — Time access and conversions" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/time.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="This module provides various time-related functions. For related functionality, see also the datetime and calendar modules. Although this module is always available, not all functions are available..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="This module provides various time-related functions. For related functionality, see also the datetime and calendar modules. Although this module is always available, not all functions are available..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>time — Time access and conversions &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="argparse — Parser for command-line options, arguments and sub-commands" href="argparse.html" />
  33. <link rel="prev" title="io — Core tools for working with streams" href="io.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/time.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code> — Time access and conversions</a><ul>
  86. <li><a class="reference internal" href="#functions">Functions</a></li>
  87. <li><a class="reference internal" href="#clock-id-constants">Clock ID Constants</a></li>
  88. <li><a class="reference internal" href="#timezone-constants">Timezone Constants</a></li>
  89. </ul>
  90. </li>
  91. </ul>
  92. </div>
  93. <div>
  94. <h4>Previous topic</h4>
  95. <p class="topless"><a href="io.html"
  96. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code> — Core tools for working with streams</a></p>
  97. </div>
  98. <div>
  99. <h4>Next topic</h4>
  100. <p class="topless"><a href="argparse.html"
  101. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code> — Parser for command-line options, arguments and sub-commands</a></p>
  102. </div>
  103. <div role="note" aria-label="source link">
  104. <h3>This Page</h3>
  105. <ul class="this-page-menu">
  106. <li><a href="../bugs.html">Report a Bug</a></li>
  107. <li>
  108. <a href="https://github.com/python/cpython/blob/main/Doc/library/time.rst"
  109. rel="nofollow">Show Source
  110. </a>
  111. </li>
  112. </ul>
  113. </div>
  114. </nav>
  115. </div>
  116. </div>
  117. <div class="related" role="navigation" aria-label="related navigation">
  118. <h3>Navigation</h3>
  119. <ul>
  120. <li class="right" style="margin-right: 10px">
  121. <a href="../genindex.html" title="General Index"
  122. accesskey="I">index</a></li>
  123. <li class="right" >
  124. <a href="../py-modindex.html" title="Python Module Index"
  125. >modules</a> |</li>
  126. <li class="right" >
  127. <a href="argparse.html" title="argparse — Parser for command-line options, arguments and sub-commands"
  128. accesskey="N">next</a> |</li>
  129. <li class="right" >
  130. <a href="io.html" title="io — Core tools for working with streams"
  131. accesskey="P">previous</a> |</li>
  132. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  133. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  134. <li class="switchers">
  135. <div class="language_switcher_placeholder"></div>
  136. <div class="version_switcher_placeholder"></div>
  137. </li>
  138. <li>
  139. </li>
  140. <li id="cpython-language-and-version">
  141. <a href="../index.html">3.12.3 Documentation</a> &#187;
  142. </li>
  143. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  144. <li class="nav-item nav-item-2"><a href="allos.html" accesskey="U">Generic Operating System Services</a> &#187;</li>
  145. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code> — Time access and conversions</a></li>
  146. <li class="right">
  147. <div class="inline-search" role="search">
  148. <form class="inline-search" action="../search.html" method="get">
  149. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  150. <input type="submit" value="Go" />
  151. </form>
  152. </div>
  153. |
  154. </li>
  155. <li class="right">
  156. <label class="theme-selector-label">
  157. Theme
  158. <select class="theme-selector" oninput="activateTheme(this.value)">
  159. <option value="auto" selected>Auto</option>
  160. <option value="light">Light</option>
  161. <option value="dark">Dark</option>
  162. </select>
  163. </label> |</li>
  164. </ul>
  165. </div>
  166. <div class="document">
  167. <div class="documentwrapper">
  168. <div class="bodywrapper">
  169. <div class="body" role="main">
  170. <section id="module-time">
  171. <span id="time-time-access-and-conversions"></span><h1><a class="reference internal" href="#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> — Time access and conversions<a class="headerlink" href="#module-time" title="Link to this heading">¶</a></h1>
  172. <hr class="docutils" />
  173. <p>This module provides various time-related functions. For related
  174. functionality, see also the <a class="reference internal" href="datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a> and <a class="reference internal" href="calendar.html#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code></a> modules.</p>
  175. <p>Although this module is always available,
  176. not all functions are available on all platforms. Most of the functions
  177. defined in this module call platform C library functions with the same name. It
  178. may sometimes be helpful to consult the platform documentation, because the
  179. semantics of these functions varies among platforms.</p>
  180. <p>An explanation of some terminology and conventions is in order.</p>
  181. <span id="epoch"></span><ul class="simple" id="index-0">
  182. <li><p>The <em class="dfn">epoch</em> is the point where the time starts, the return value of
  183. <code class="docutils literal notranslate"><span class="pre">time.gmtime(0)</span></code>. It is January 1, 1970, 00:00:00 (UTC) on all platforms.</p></li>
  184. </ul>
  185. <ul class="simple" id="index-1">
  186. <li><p>The term <em class="dfn">seconds since the epoch</em> refers to the total number
  187. of elapsed seconds since the epoch, typically excluding
  188. <a class="reference external" href="https://en.wikipedia.org/wiki/Leap_second">leap seconds</a>. Leap seconds are excluded from this total on all
  189. POSIX-compliant platforms.</p></li>
  190. </ul>
  191. <ul class="simple" id="index-2">
  192. <li><p>The functions in this module may not handle dates and times before the <a class="reference internal" href="#epoch">epoch</a> or
  193. far in the future. The cut-off point in the future is determined by the C
  194. library; for 32-bit systems, it is typically in 2038.</p></li>
  195. </ul>
  196. <ul class="simple" id="index-3">
  197. <li><p>Function <a class="reference internal" href="#time.strptime" title="time.strptime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strptime()</span></code></a> can parse 2-digit years when given <code class="docutils literal notranslate"><span class="pre">%y</span></code> format
  198. code. When 2-digit years are parsed, they are converted according to the POSIX
  199. and ISO C standards: values 69–99 are mapped to 1969–1999, and values 0–68
  200. are mapped to 2000–2068.</p></li>
  201. </ul>
  202. <ul class="simple" id="index-4">
  203. <li><p>UTC is Coordinated Universal Time (formerly known as Greenwich Mean Time, or
  204. GMT). The acronym UTC is not a mistake but a compromise between English and
  205. French.</p></li>
  206. </ul>
  207. <ul id="index-5">
  208. <li><p>DST is Daylight Saving Time, an adjustment of the timezone by (usually) one
  209. hour during part of the year. DST rules are magic (determined by local law) and
  210. can change from year to year. The C library has a table containing the local
  211. rules (often it is read from a system file for flexibility) and is the only
  212. source of True Wisdom in this respect.</p></li>
  213. <li><p>The precision of the various real-time functions may be less than suggested by
  214. the units in which their value or argument is expressed. E.g. on most Unix
  215. systems, the clock “ticks” only 50 or 100 times a second.</p></li>
  216. <li><p>On the other hand, the precision of <a class="reference internal" href="#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time()</span></code></a> and <a class="reference internal" href="#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">sleep()</span></code></a> is better
  217. than their Unix equivalents: times are expressed as floating point numbers,
  218. <a class="reference internal" href="#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time()</span></code></a> returns the most accurate time available (using Unix
  219. <code class="xref c c-func docutils literal notranslate"><span class="pre">gettimeofday()</span></code> where available), and <a class="reference internal" href="#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">sleep()</span></code></a> will accept a time
  220. with a nonzero fraction (Unix <code class="xref c c-func docutils literal notranslate"><span class="pre">select()</span></code> is used to implement this, where
  221. available).</p></li>
  222. <li><p>The time value as returned by <a class="reference internal" href="#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a>, <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a>, and
  223. <a class="reference internal" href="#time.strptime" title="time.strptime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strptime()</span></code></a>, and accepted by <a class="reference internal" href="#time.asctime" title="time.asctime"><code class="xref py py-func docutils literal notranslate"><span class="pre">asctime()</span></code></a>, <a class="reference internal" href="#time.mktime" title="time.mktime"><code class="xref py py-func docutils literal notranslate"><span class="pre">mktime()</span></code></a> and
  224. <a class="reference internal" href="#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a>, is a sequence of 9 integers. The return values of
  225. <a class="reference internal" href="#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a>, <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a>, and <a class="reference internal" href="#time.strptime" title="time.strptime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strptime()</span></code></a> also offer attribute
  226. names for individual fields.</p>
  227. <p>See <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> for a description of these objects.</p>
  228. <div class="versionchanged">
  229. <p><span class="versionmodified changed">Changed in version 3.3: </span>The <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> type was extended to provide
  230. the <a class="reference internal" href="#time.struct_time.tm_gmtoff" title="time.struct_time.tm_gmtoff"><code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_gmtoff</span></code></a> and <a class="reference internal" href="#time.struct_time.tm_zone" title="time.struct_time.tm_zone"><code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_zone</span></code></a>
  231. attributes when platform supports corresponding
  232. <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">tm</span></code> members.</p>
  233. </div>
  234. <div class="versionchanged">
  235. <p><span class="versionmodified changed">Changed in version 3.6: </span>The <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> attributes
  236. <a class="reference internal" href="#time.struct_time.tm_gmtoff" title="time.struct_time.tm_gmtoff"><code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_gmtoff</span></code></a> and <a class="reference internal" href="#time.struct_time.tm_zone" title="time.struct_time.tm_zone"><code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_zone</span></code></a>
  237. are now available on all platforms.</p>
  238. </div>
  239. </li>
  240. <li><p>Use the following functions to convert between time representations:</p>
  241. <table class="docutils align-default">
  242. <thead>
  243. <tr class="row-odd"><th class="head"><p>From</p></th>
  244. <th class="head"><p>To</p></th>
  245. <th class="head"><p>Use</p></th>
  246. </tr>
  247. </thead>
  248. <tbody>
  249. <tr class="row-even"><td><p>seconds since the epoch</p></td>
  250. <td><p><a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> in
  251. UTC</p></td>
  252. <td><p><a class="reference internal" href="#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a></p></td>
  253. </tr>
  254. <tr class="row-odd"><td><p>seconds since the epoch</p></td>
  255. <td><p><a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> in
  256. local time</p></td>
  257. <td><p><a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a></p></td>
  258. </tr>
  259. <tr class="row-even"><td><p><a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> in
  260. UTC</p></td>
  261. <td><p>seconds since the epoch</p></td>
  262. <td><p><a class="reference internal" href="calendar.html#calendar.timegm" title="calendar.timegm"><code class="xref py py-func docutils literal notranslate"><span class="pre">calendar.timegm()</span></code></a></p></td>
  263. </tr>
  264. <tr class="row-odd"><td><p><a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> in
  265. local time</p></td>
  266. <td><p>seconds since the epoch</p></td>
  267. <td><p><a class="reference internal" href="#time.mktime" title="time.mktime"><code class="xref py py-func docutils literal notranslate"><span class="pre">mktime()</span></code></a></p></td>
  268. </tr>
  269. </tbody>
  270. </table>
  271. </li>
  272. </ul>
  273. <section id="functions">
  274. <span id="time-functions"></span><h2>Functions<a class="headerlink" href="#functions" title="Link to this heading">¶</a></h2>
  275. <dl class="py function">
  276. <dt class="sig sig-object py" id="time.asctime">
  277. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">asctime</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">t</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#time.asctime" title="Link to this definition">¶</a></dt>
  278. <dd><p>Convert a tuple or <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> representing a time as returned by
  279. <a class="reference internal" href="#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a> or <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a> to a string of the following
  280. form: <code class="docutils literal notranslate"><span class="pre">'Sun</span> <span class="pre">Jun</span> <span class="pre">20</span> <span class="pre">23:21:05</span> <span class="pre">1993'</span></code>. The day field is two characters long
  281. and is space padded if the day is a single digit,
  282. e.g.: <code class="docutils literal notranslate"><span class="pre">'Wed</span> <span class="pre">Jun</span>&#160; <span class="pre">9</span> <span class="pre">04:26:40</span> <span class="pre">1993'</span></code>.</p>
  283. <p>If <em>t</em> is not provided, the current time as returned by <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a>
  284. is used. Locale information is not used by <a class="reference internal" href="#time.asctime" title="time.asctime"><code class="xref py py-func docutils literal notranslate"><span class="pre">asctime()</span></code></a>.</p>
  285. <div class="admonition note">
  286. <p class="admonition-title">Note</p>
  287. <p>Unlike the C function of the same name, <a class="reference internal" href="#time.asctime" title="time.asctime"><code class="xref py py-func docutils literal notranslate"><span class="pre">asctime()</span></code></a> does not add a
  288. trailing newline.</p>
  289. </div>
  290. </dd></dl>
  291. <dl class="py function">
  292. <dt class="sig sig-object py" id="time.pthread_getcpuclockid">
  293. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">pthread_getcpuclockid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">thread_id</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#time.pthread_getcpuclockid" title="Link to this definition">¶</a></dt>
  294. <dd><p>Return the <em>clk_id</em> of the thread-specific CPU-time clock for the specified <em>thread_id</em>.</p>
  295. <p>Use <a class="reference internal" href="threading.html#threading.get_ident" title="threading.get_ident"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.get_ident()</span></code></a> or the <a class="reference internal" href="threading.html#threading.Thread.ident" title="threading.Thread.ident"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ident</span></code></a>
  296. attribute of <a class="reference internal" href="threading.html#threading.Thread" title="threading.Thread"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Thread</span></code></a> objects to get a suitable value
  297. for <em>thread_id</em>.</p>
  298. <div class="admonition warning">
  299. <p class="admonition-title">Warning</p>
  300. <p>Passing an invalid or expired <em>thread_id</em> may result in
  301. undefined behavior, such as segmentation fault.</p>
  302. </div>
  303. <div class="availability docutils container">
  304. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix</p>
  305. <p>See the man page for <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/pthread_getcpuclockid(3)">pthread_getcpuclockid(3)</a></em> for
  306. further information.</p>
  307. </div>
  308. <div class="versionadded">
  309. <p><span class="versionmodified added">New in version 3.7.</span></p>
  310. </div>
  311. </dd></dl>
  312. <dl class="py function">
  313. <dt class="sig sig-object py" id="time.clock_getres">
  314. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">clock_getres</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">clk_id</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#time.clock_getres" title="Link to this definition">¶</a></dt>
  315. <dd><p>Return the resolution (precision) of the specified clock <em>clk_id</em>. Refer to
  316. <a class="reference internal" href="#time-clock-id-constants"><span class="std std-ref">Clock ID Constants</span></a> for a list of accepted values for <em>clk_id</em>.</p>
  317. <div class="availability docutils container">
  318. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  319. </div>
  320. <div class="versionadded">
  321. <p><span class="versionmodified added">New in version 3.3.</span></p>
  322. </div>
  323. </dd></dl>
  324. <dl class="py function">
  325. <dt class="sig sig-object py" id="time.clock_gettime">
  326. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">clock_gettime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">clk_id</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#float" title="float"><span class="pre">float</span></a></span></span><a class="headerlink" href="#time.clock_gettime" title="Link to this definition">¶</a></dt>
  327. <dd><p>Return the time of the specified clock <em>clk_id</em>. Refer to
  328. <a class="reference internal" href="#time-clock-id-constants"><span class="std std-ref">Clock ID Constants</span></a> for a list of accepted values for <em>clk_id</em>.</p>
  329. <p>Use <a class="reference internal" href="#time.clock_gettime_ns" title="time.clock_gettime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_gettime_ns()</span></code></a> to avoid the precision loss caused by the
  330. <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> type.</p>
  331. <div class="availability docutils container">
  332. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  333. </div>
  334. <div class="versionadded">
  335. <p><span class="versionmodified added">New in version 3.3.</span></p>
  336. </div>
  337. </dd></dl>
  338. <dl class="py function">
  339. <dt class="sig sig-object py" id="time.clock_gettime_ns">
  340. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">clock_gettime_ns</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">clk_id</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#int" title="int"><span class="pre">int</span></a></span></span><a class="headerlink" href="#time.clock_gettime_ns" title="Link to this definition">¶</a></dt>
  341. <dd><p>Similar to <a class="reference internal" href="#time.clock_gettime" title="time.clock_gettime"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_gettime()</span></code></a> but return time as nanoseconds.</p>
  342. <div class="availability docutils container">
  343. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  344. </div>
  345. <div class="versionadded">
  346. <p><span class="versionmodified added">New in version 3.7.</span></p>
  347. </div>
  348. </dd></dl>
  349. <dl class="py function">
  350. <dt class="sig sig-object py" id="time.clock_settime">
  351. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">clock_settime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">clk_id</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">time</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="functions.html#float" title="float"><span class="pre">float</span></a></span></em><span class="sig-paren">)</span><a class="headerlink" href="#time.clock_settime" title="Link to this definition">¶</a></dt>
  352. <dd><p>Set the time of the specified clock <em>clk_id</em>. Currently,
  353. <a class="reference internal" href="#time.CLOCK_REALTIME" title="time.CLOCK_REALTIME"><code class="xref py py-data docutils literal notranslate"><span class="pre">CLOCK_REALTIME</span></code></a> is the only accepted value for <em>clk_id</em>.</p>
  354. <p>Use <a class="reference internal" href="#time.clock_settime_ns" title="time.clock_settime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_settime_ns()</span></code></a> to avoid the precision loss caused by the
  355. <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> type.</p>
  356. <div class="availability docutils container">
  357. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  358. </div>
  359. <div class="versionadded">
  360. <p><span class="versionmodified added">New in version 3.3.</span></p>
  361. </div>
  362. </dd></dl>
  363. <dl class="py function">
  364. <dt class="sig sig-object py" id="time.clock_settime_ns">
  365. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">clock_settime_ns</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">clk_id</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">time</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="functions.html#int" title="int"><span class="pre">int</span></a></span></em><span class="sig-paren">)</span><a class="headerlink" href="#time.clock_settime_ns" title="Link to this definition">¶</a></dt>
  366. <dd><p>Similar to <a class="reference internal" href="#time.clock_settime" title="time.clock_settime"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_settime()</span></code></a> but set time with nanoseconds.</p>
  367. <div class="availability docutils container">
  368. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  369. </div>
  370. <div class="versionadded">
  371. <p><span class="versionmodified added">New in version 3.7.</span></p>
  372. </div>
  373. </dd></dl>
  374. <dl class="py function">
  375. <dt class="sig sig-object py" id="time.ctime">
  376. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">ctime</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">secs</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#time.ctime" title="Link to this definition">¶</a></dt>
  377. <dd><p>Convert a time expressed in seconds since the <a class="reference internal" href="#epoch">epoch</a> to a string of a form:
  378. <code class="docutils literal notranslate"><span class="pre">'Sun</span> <span class="pre">Jun</span> <span class="pre">20</span> <span class="pre">23:21:05</span> <span class="pre">1993'</span></code> representing local time. The day field
  379. is two characters long and is space padded if the day is a single digit,
  380. e.g.: <code class="docutils literal notranslate"><span class="pre">'Wed</span> <span class="pre">Jun</span>&#160; <span class="pre">9</span> <span class="pre">04:26:40</span> <span class="pre">1993'</span></code>.</p>
  381. <p>If <em>secs</em> is not provided or <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>, the current time as
  382. returned by <a class="reference internal" href="#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time()</span></code></a> is used. <code class="docutils literal notranslate"><span class="pre">ctime(secs)</span></code> is equivalent to
  383. <code class="docutils literal notranslate"><span class="pre">asctime(localtime(secs))</span></code>. Locale information is not used by
  384. <a class="reference internal" href="#time.ctime" title="time.ctime"><code class="xref py py-func docutils literal notranslate"><span class="pre">ctime()</span></code></a>.</p>
  385. </dd></dl>
  386. <dl class="py function">
  387. <dt class="sig sig-object py" id="time.get_clock_info">
  388. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">get_clock_info</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#time.get_clock_info" title="Link to this definition">¶</a></dt>
  389. <dd><p>Get information on the specified clock as a namespace object.
  390. Supported clock names and the corresponding functions to read their value
  391. are:</p>
  392. <ul class="simple">
  393. <li><p><code class="docutils literal notranslate"><span class="pre">'monotonic'</span></code>: <a class="reference internal" href="#time.monotonic" title="time.monotonic"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.monotonic()</span></code></a></p></li>
  394. <li><p><code class="docutils literal notranslate"><span class="pre">'perf_counter'</span></code>: <a class="reference internal" href="#time.perf_counter" title="time.perf_counter"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.perf_counter()</span></code></a></p></li>
  395. <li><p><code class="docutils literal notranslate"><span class="pre">'process_time'</span></code>: <a class="reference internal" href="#time.process_time" title="time.process_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.process_time()</span></code></a></p></li>
  396. <li><p><code class="docutils literal notranslate"><span class="pre">'thread_time'</span></code>: <a class="reference internal" href="#time.thread_time" title="time.thread_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.thread_time()</span></code></a></p></li>
  397. <li><p><code class="docutils literal notranslate"><span class="pre">'time'</span></code>: <a class="reference internal" href="#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time()</span></code></a></p></li>
  398. </ul>
  399. <p>The result has the following attributes:</p>
  400. <ul class="simple">
  401. <li><p><em>adjustable</em>: <code class="docutils literal notranslate"><span class="pre">True</span></code> if the clock can be changed automatically (e.g. by
  402. a NTP daemon) or manually by the system administrator, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise</p></li>
  403. <li><p><em>implementation</em>: The name of the underlying C function used to get
  404. the clock value. Refer to <a class="reference internal" href="#time-clock-id-constants"><span class="std std-ref">Clock ID Constants</span></a> for possible values.</p></li>
  405. <li><p><em>monotonic</em>: <code class="docutils literal notranslate"><span class="pre">True</span></code> if the clock cannot go backward,
  406. <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise</p></li>
  407. <li><p><em>resolution</em>: The resolution of the clock in seconds (<a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>)</p></li>
  408. </ul>
  409. <div class="versionadded">
  410. <p><span class="versionmodified added">New in version 3.3.</span></p>
  411. </div>
  412. </dd></dl>
  413. <dl class="py function">
  414. <dt class="sig sig-object py" id="time.gmtime">
  415. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">gmtime</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">secs</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#time.gmtime" title="Link to this definition">¶</a></dt>
  416. <dd><p>Convert a time expressed in seconds since the <a class="reference internal" href="#epoch">epoch</a> to a <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> in
  417. UTC in which the dst flag is always zero. If <em>secs</em> is not provided or
  418. <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>, the current time as returned by <a class="reference internal" href="#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time()</span></code></a> is used. Fractions
  419. of a second are ignored. See above for a description of the
  420. <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> object. See <a class="reference internal" href="calendar.html#calendar.timegm" title="calendar.timegm"><code class="xref py py-func docutils literal notranslate"><span class="pre">calendar.timegm()</span></code></a> for the inverse of this
  421. function.</p>
  422. </dd></dl>
  423. <dl class="py function">
  424. <dt class="sig sig-object py" id="time.localtime">
  425. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">localtime</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">secs</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#time.localtime" title="Link to this definition">¶</a></dt>
  426. <dd><p>Like <a class="reference internal" href="#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a> but converts to local time. If <em>secs</em> is not provided or
  427. <a class="reference internal" href="constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>, the current time as returned by <a class="reference internal" href="#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time()</span></code></a> is used. The dst
  428. flag is set to <code class="docutils literal notranslate"><span class="pre">1</span></code> when DST applies to the given time.</p>
  429. <p><a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a> may raise <a class="reference internal" href="exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a>, if the timestamp is
  430. outside the range of values supported by the platform C <code class="xref c c-func docutils literal notranslate"><span class="pre">localtime()</span></code>
  431. or <code class="xref c c-func docutils literal notranslate"><span class="pre">gmtime()</span></code> functions, and <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> on <code class="xref c c-func docutils literal notranslate"><span class="pre">localtime()</span></code> or
  432. <code class="xref c c-func docutils literal notranslate"><span class="pre">gmtime()</span></code> failure. It’s common for this to be restricted to years
  433. between 1970 and 2038.</p>
  434. </dd></dl>
  435. <dl class="py function">
  436. <dt class="sig sig-object py" id="time.mktime">
  437. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">mktime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">t</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#time.mktime" title="Link to this definition">¶</a></dt>
  438. <dd><p>This is the inverse function of <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a>. Its argument is the
  439. <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> or full 9-tuple (since the dst flag is needed; use <code class="docutils literal notranslate"><span class="pre">-1</span></code>
  440. as the dst flag if it is unknown) which expresses the time in <em>local</em> time, not
  441. UTC. It returns a floating point number, for compatibility with <a class="reference internal" href="#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time()</span></code></a>.
  442. If the input value cannot be represented as a valid time, either
  443. <a class="reference internal" href="exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a> or <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> will be raised (which depends on
  444. whether the invalid value is caught by Python or the underlying C libraries).
  445. The earliest date for which it can generate a time is platform-dependent.</p>
  446. </dd></dl>
  447. <dl class="py function">
  448. <dt class="sig sig-object py" id="time.monotonic">
  449. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">monotonic</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#float" title="float"><span class="pre">float</span></a></span></span><a class="headerlink" href="#time.monotonic" title="Link to this definition">¶</a></dt>
  450. <dd><p>Return the value (in fractional seconds) of a monotonic clock, i.e. a clock
  451. that cannot go backwards. The clock is not affected by system clock updates.
  452. The reference point of the returned value is undefined, so that only the
  453. difference between the results of two calls is valid.</p>
  454. <p>Use <a class="reference internal" href="#time.monotonic_ns" title="time.monotonic_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">monotonic_ns()</span></code></a> to avoid the precision loss caused by the
  455. <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> type.</p>
  456. <div class="versionadded">
  457. <p><span class="versionmodified added">New in version 3.3.</span></p>
  458. </div>
  459. <div class="versionchanged">
  460. <p><span class="versionmodified changed">Changed in version 3.5: </span>The function is now always available and always system-wide.</p>
  461. </div>
  462. <div class="versionchanged">
  463. <p><span class="versionmodified changed">Changed in version 3.10: </span>On macOS, the function is now system-wide.</p>
  464. </div>
  465. </dd></dl>
  466. <dl class="py function">
  467. <dt class="sig sig-object py" id="time.monotonic_ns">
  468. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">monotonic_ns</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#int" title="int"><span class="pre">int</span></a></span></span><a class="headerlink" href="#time.monotonic_ns" title="Link to this definition">¶</a></dt>
  469. <dd><p>Similar to <a class="reference internal" href="#time.monotonic" title="time.monotonic"><code class="xref py py-func docutils literal notranslate"><span class="pre">monotonic()</span></code></a>, but return time as nanoseconds.</p>
  470. <div class="versionadded">
  471. <p><span class="versionmodified added">New in version 3.7.</span></p>
  472. </div>
  473. </dd></dl>
  474. <dl class="py function">
  475. <dt class="sig sig-object py" id="time.perf_counter">
  476. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">perf_counter</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#float" title="float"><span class="pre">float</span></a></span></span><a class="headerlink" href="#time.perf_counter" title="Link to this definition">¶</a></dt>
  477. <dd><p id="index-6">Return the value (in fractional seconds) of a performance counter, i.e. a
  478. clock with the highest available resolution to measure a short duration. It
  479. does include time elapsed during sleep and is system-wide. The reference
  480. point of the returned value is undefined, so that only the difference between
  481. the results of two calls is valid.</p>
  482. <p>Use <a class="reference internal" href="#time.perf_counter_ns" title="time.perf_counter_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">perf_counter_ns()</span></code></a> to avoid the precision loss caused by the
  483. <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> type.</p>
  484. <div class="versionadded">
  485. <p><span class="versionmodified added">New in version 3.3.</span></p>
  486. </div>
  487. <div class="versionchanged">
  488. <p><span class="versionmodified changed">Changed in version 3.10: </span>On Windows, the function is now system-wide.</p>
  489. </div>
  490. </dd></dl>
  491. <dl class="py function">
  492. <dt class="sig sig-object py" id="time.perf_counter_ns">
  493. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">perf_counter_ns</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#int" title="int"><span class="pre">int</span></a></span></span><a class="headerlink" href="#time.perf_counter_ns" title="Link to this definition">¶</a></dt>
  494. <dd><p>Similar to <a class="reference internal" href="#time.perf_counter" title="time.perf_counter"><code class="xref py py-func docutils literal notranslate"><span class="pre">perf_counter()</span></code></a>, but return time as nanoseconds.</p>
  495. <div class="versionadded">
  496. <p><span class="versionmodified added">New in version 3.7.</span></p>
  497. </div>
  498. </dd></dl>
  499. <dl class="py function">
  500. <dt class="sig sig-object py" id="time.process_time">
  501. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">process_time</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#float" title="float"><span class="pre">float</span></a></span></span><a class="headerlink" href="#time.process_time" title="Link to this definition">¶</a></dt>
  502. <dd><p id="index-7">Return the value (in fractional seconds) of the sum of the system and user
  503. CPU time of the current process. It does not include time elapsed during
  504. sleep. It is process-wide by definition. The reference point of the
  505. returned value is undefined, so that only the difference between the results
  506. of two calls is valid.</p>
  507. <p>Use <a class="reference internal" href="#time.process_time_ns" title="time.process_time_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">process_time_ns()</span></code></a> to avoid the precision loss caused by the
  508. <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> type.</p>
  509. <div class="versionadded">
  510. <p><span class="versionmodified added">New in version 3.3.</span></p>
  511. </div>
  512. </dd></dl>
  513. <dl class="py function">
  514. <dt class="sig sig-object py" id="time.process_time_ns">
  515. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">process_time_ns</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#int" title="int"><span class="pre">int</span></a></span></span><a class="headerlink" href="#time.process_time_ns" title="Link to this definition">¶</a></dt>
  516. <dd><p>Similar to <a class="reference internal" href="#time.process_time" title="time.process_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">process_time()</span></code></a> but return time as nanoseconds.</p>
  517. <div class="versionadded">
  518. <p><span class="versionmodified added">New in version 3.7.</span></p>
  519. </div>
  520. </dd></dl>
  521. <dl class="py function">
  522. <dt class="sig sig-object py" id="time.sleep">
  523. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">sleep</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">secs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#time.sleep" title="Link to this definition">¶</a></dt>
  524. <dd><p>Suspend execution of the calling thread for the given number of seconds.
  525. The argument may be a floating point number to indicate a more precise sleep
  526. time.</p>
  527. <p>If the sleep is interrupted by a signal and no exception is raised by the
  528. signal handler, the sleep is restarted with a recomputed timeout.</p>
  529. <p>The suspension time may be longer than requested by an arbitrary amount,
  530. because of the scheduling of other activity in the system.</p>
  531. <p>On Windows, if <em>secs</em> is zero, the thread relinquishes the remainder of its
  532. time slice to any other thread that is ready to run. If there are no other
  533. threads ready to run, the function returns immediately, and the thread
  534. continues execution. On Windows 8.1 and newer the implementation uses
  535. a <a class="reference external" href="https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers">high-resolution timer</a>
  536. which provides resolution of 100 nanoseconds. If <em>secs</em> is zero, <code class="docutils literal notranslate"><span class="pre">Sleep(0)</span></code> is used.</p>
  537. <p>Unix implementation:</p>
  538. <ul class="simple">
  539. <li><p>Use <code class="docutils literal notranslate"><span class="pre">clock_nanosleep()</span></code> if available (resolution: 1 nanosecond);</p></li>
  540. <li><p>Or use <code class="docutils literal notranslate"><span class="pre">nanosleep()</span></code> if available (resolution: 1 nanosecond);</p></li>
  541. <li><p>Or use <code class="docutils literal notranslate"><span class="pre">select()</span></code> (resolution: 1 microsecond).</p></li>
  542. </ul>
  543. <div class="versionchanged">
  544. <p><span class="versionmodified changed">Changed in version 3.5: </span>The function now sleeps at least <em>secs</em> even if the sleep is interrupted
  545. by a signal, except if the signal handler raises an exception (see
  546. <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> for the rationale).</p>
  547. </div>
  548. <div class="versionchanged">
  549. <p><span class="versionmodified changed">Changed in version 3.11: </span>On Unix, the <code class="docutils literal notranslate"><span class="pre">clock_nanosleep()</span></code> and <code class="docutils literal notranslate"><span class="pre">nanosleep()</span></code> functions are now
  550. used if available. On Windows, a waitable timer is now used.</p>
  551. </div>
  552. </dd></dl>
  553. <dl class="py function" id="index-9">
  554. <dt class="sig sig-object py" id="time.strftime">
  555. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">strftime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">format</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">t</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#time.strftime" title="Link to this definition">¶</a></dt>
  556. <dd><p>Convert a tuple or <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> representing a time as returned by
  557. <a class="reference internal" href="#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a> or <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a> to a string as specified by the <em>format</em>
  558. argument. If <em>t</em> is not provided, the current time as returned by
  559. <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a> is used. <em>format</em> must be a string. <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is
  560. raised if any field in <em>t</em> is outside of the allowed range.</p>
  561. <p>0 is a legal argument for any position in the time tuple; if it is normally
  562. illegal the value is forced to a correct one.</p>
  563. <p>The following directives can be embedded in the <em>format</em> string. They are shown
  564. without the optional field width and precision specification, and are replaced
  565. by the indicated characters in the <a class="reference internal" href="#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> result:</p>
  566. <table class="docutils align-default">
  567. <thead>
  568. <tr class="row-odd"><th class="head"><p>Directive</p></th>
  569. <th class="head"><p>Meaning</p></th>
  570. <th class="head"><p>Notes</p></th>
  571. </tr>
  572. </thead>
  573. <tbody>
  574. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%a</span></code></p></td>
  575. <td><p>Locale’s abbreviated weekday name.</p></td>
  576. <td></td>
  577. </tr>
  578. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%A</span></code></p></td>
  579. <td><p>Locale’s full weekday name.</p></td>
  580. <td></td>
  581. </tr>
  582. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%b</span></code></p></td>
  583. <td><p>Locale’s abbreviated month name.</p></td>
  584. <td></td>
  585. </tr>
  586. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%B</span></code></p></td>
  587. <td><p>Locale’s full month name.</p></td>
  588. <td></td>
  589. </tr>
  590. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%c</span></code></p></td>
  591. <td><p>Locale’s appropriate date and time
  592. representation.</p></td>
  593. <td></td>
  594. </tr>
  595. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%d</span></code></p></td>
  596. <td><p>Day of the month as a decimal number [01,31].</p></td>
  597. <td></td>
  598. </tr>
  599. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%f</span></code></p></td>
  600. <td><dl class="simple">
  601. <dt>Microseconds as a decimal number</dt><dd><p>[000000,999999].</p>
  602. </dd>
  603. </dl>
  604. </td>
  605. <td><p>(1)</p></td>
  606. </tr>
  607. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%H</span></code></p></td>
  608. <td><p>Hour (24-hour clock) as a decimal number
  609. [00,23].</p></td>
  610. <td></td>
  611. </tr>
  612. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%I</span></code></p></td>
  613. <td><p>Hour (12-hour clock) as a decimal number
  614. [01,12].</p></td>
  615. <td></td>
  616. </tr>
  617. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%j</span></code></p></td>
  618. <td><p>Day of the year as a decimal number [001,366].</p></td>
  619. <td></td>
  620. </tr>
  621. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%m</span></code></p></td>
  622. <td><p>Month as a decimal number [01,12].</p></td>
  623. <td></td>
  624. </tr>
  625. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%M</span></code></p></td>
  626. <td><p>Minute as a decimal number [00,59].</p></td>
  627. <td></td>
  628. </tr>
  629. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%p</span></code></p></td>
  630. <td><p>Locale’s equivalent of either AM or PM.</p></td>
  631. <td><p>(2)</p></td>
  632. </tr>
  633. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%S</span></code></p></td>
  634. <td><p>Second as a decimal number [00,61].</p></td>
  635. <td><p>(3)</p></td>
  636. </tr>
  637. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%U</span></code></p></td>
  638. <td><p>Week number of the year (Sunday as the first
  639. day of the week) as a decimal number [00,53].
  640. All days in a new year preceding the first
  641. Sunday are considered to be in week 0.</p></td>
  642. <td><p>(4)</p></td>
  643. </tr>
  644. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%w</span></code></p></td>
  645. <td><p>Weekday as a decimal number [0(Sunday),6].</p></td>
  646. <td></td>
  647. </tr>
  648. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%W</span></code></p></td>
  649. <td><p>Week number of the year (Monday as the first
  650. day of the week) as a decimal number [00,53].
  651. All days in a new year preceding the first
  652. Monday are considered to be in week 0.</p></td>
  653. <td><p>(4)</p></td>
  654. </tr>
  655. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%x</span></code></p></td>
  656. <td><p>Locale’s appropriate date representation.</p></td>
  657. <td></td>
  658. </tr>
  659. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%X</span></code></p></td>
  660. <td><p>Locale’s appropriate time representation.</p></td>
  661. <td></td>
  662. </tr>
  663. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%y</span></code></p></td>
  664. <td><p>Year without century as a decimal number
  665. [00,99].</p></td>
  666. <td></td>
  667. </tr>
  668. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%Y</span></code></p></td>
  669. <td><p>Year with century as a decimal number.</p></td>
  670. <td></td>
  671. </tr>
  672. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%z</span></code></p></td>
  673. <td><p>Time zone offset indicating a positive or
  674. negative time difference from UTC/GMT of the
  675. form +HHMM or -HHMM, where H represents decimal
  676. hour digits and M represents decimal minute
  677. digits [-23:59, +23:59]. <a class="footnote-reference brackets" href="#id4" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p></td>
  678. <td></td>
  679. </tr>
  680. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">%Z</span></code></p></td>
  681. <td><p>Time zone name (no characters if no time zone
  682. exists). Deprecated. <a class="footnote-reference brackets" href="#id4" id="id2" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p></td>
  683. <td></td>
  684. </tr>
  685. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">%%</span></code></p></td>
  686. <td><p>A literal <code class="docutils literal notranslate"><span class="pre">'%'</span></code> character.</p></td>
  687. <td></td>
  688. </tr>
  689. </tbody>
  690. </table>
  691. <p>Notes:</p>
  692. <ol class="arabic simple">
  693. <li><p>The <code class="docutils literal notranslate"><span class="pre">%f</span></code> format directive only applies to <a class="reference internal" href="#time.strptime" title="time.strptime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strptime()</span></code></a>,
  694. not to <a class="reference internal" href="#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a>. However, see also <a class="reference internal" href="datetime.html#datetime.datetime.strptime" title="datetime.datetime.strptime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.strptime()</span></code></a> and
  695. <a class="reference internal" href="datetime.html#datetime.datetime.strftime" title="datetime.datetime.strftime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.strftime()</span></code></a> where the <code class="docutils literal notranslate"><span class="pre">%f</span></code> format directive
  696. <a class="reference internal" href="datetime.html#format-codes"><span class="std std-ref">applies to microseconds</span></a>.</p></li>
  697. <li><p>When used with the <a class="reference internal" href="#time.strptime" title="time.strptime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strptime()</span></code></a> function, the <code class="docutils literal notranslate"><span class="pre">%p</span></code> directive only affects
  698. the output hour field if the <code class="docutils literal notranslate"><span class="pre">%I</span></code> directive is used to parse the hour.</p></li>
  699. </ol>
  700. <ol class="arabic simple" id="leap-second" start="3">
  701. <li><p>The range really is <code class="docutils literal notranslate"><span class="pre">0</span></code> to <code class="docutils literal notranslate"><span class="pre">61</span></code>; value <code class="docutils literal notranslate"><span class="pre">60</span></code> is valid in
  702. timestamps representing <a class="reference external" href="https://en.wikipedia.org/wiki/Leap_second">leap seconds</a> and value <code class="docutils literal notranslate"><span class="pre">61</span></code> is supported
  703. for historical reasons.</p></li>
  704. <li><p>When used with the <a class="reference internal" href="#time.strptime" title="time.strptime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strptime()</span></code></a> function, <code class="docutils literal notranslate"><span class="pre">%U</span></code> and <code class="docutils literal notranslate"><span class="pre">%W</span></code> are only used in
  705. calculations when the day of the week and the year are specified.</p></li>
  706. </ol>
  707. <p>Here is an example, a format for dates compatible with that specified in the
  708. <span class="target" id="index-10"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2822.html"><strong>RFC 2822</strong></a> Internet email standard. <a class="footnote-reference brackets" href="#id4" id="id3" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p>
  709. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">time</span> <span class="kn">import</span> <span class="n">gmtime</span><span class="p">,</span> <span class="n">strftime</span>
  710. <span class="gp">&gt;&gt;&gt; </span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%a</span><span class="s2">, </span><span class="si">%d</span><span class="s2"> %b %Y %H:%M:%S +0000&quot;</span><span class="p">,</span> <span class="n">gmtime</span><span class="p">())</span>
  711. <span class="go">&#39;Thu, 28 Jun 2001 14:17:15 +0000&#39;</span>
  712. </pre></div>
  713. </div>
  714. <p>Additional directives may be supported on certain platforms, but only the
  715. ones listed here have a meaning standardized by ANSI C. To see the full set
  716. of format codes supported on your platform, consult the <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/strftime(3)">strftime(3)</a></em>
  717. documentation.</p>
  718. <p>On some platforms, an optional field width and precision specification can
  719. immediately follow the initial <code class="docutils literal notranslate"><span class="pre">'%'</span></code> of a directive in the following order;
  720. this is also not portable. The field width is normally 2 except for <code class="docutils literal notranslate"><span class="pre">%j</span></code> where
  721. it is 3.</p>
  722. </dd></dl>
  723. <dl class="py function" id="index-11">
  724. <dt class="sig sig-object py" id="time.strptime">
  725. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">strptime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">format</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#time.strptime" title="Link to this definition">¶</a></dt>
  726. <dd><p>Parse a string representing a time according to a format. The return value
  727. is a <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> as returned by <a class="reference internal" href="#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a> or
  728. <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a>.</p>
  729. <p>The <em>format</em> parameter uses the same directives as those used by
  730. <a class="reference internal" href="#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a>; it defaults to <code class="docutils literal notranslate"><span class="pre">&quot;%a</span> <span class="pre">%b</span> <span class="pre">%d</span> <span class="pre">%H:%M:%S</span> <span class="pre">%Y&quot;</span></code> which matches the
  731. formatting returned by <a class="reference internal" href="#time.ctime" title="time.ctime"><code class="xref py py-func docutils literal notranslate"><span class="pre">ctime()</span></code></a>. If <em>string</em> cannot be parsed according
  732. to <em>format</em>, or if it has excess data after parsing, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is
  733. raised. The default values used to fill in any missing data when more
  734. accurate values cannot be inferred are <code class="docutils literal notranslate"><span class="pre">(1900,</span> <span class="pre">1,</span> <span class="pre">1,</span> <span class="pre">0,</span> <span class="pre">0,</span> <span class="pre">0,</span> <span class="pre">0,</span> <span class="pre">1,</span> <span class="pre">-1)</span></code>.
  735. Both <em>string</em> and <em>format</em> must be strings.</p>
  736. <p>For example:</p>
  737. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">time</span>
  738. <span class="gp">&gt;&gt;&gt; </span><span class="n">time</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="s2">&quot;30 Nov 00&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">%d</span><span class="s2"> %b %y&quot;</span><span class="p">)</span>
  739. <span class="go">time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0, tm_min=0,</span>
  740. <span class="go"> tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1)</span>
  741. </pre></div>
  742. </div>
  743. <p>Support for the <code class="docutils literal notranslate"><span class="pre">%Z</span></code> directive is based on the values contained in <code class="docutils literal notranslate"><span class="pre">tzname</span></code>
  744. and whether <code class="docutils literal notranslate"><span class="pre">daylight</span></code> is true. Because of this, it is platform-specific
  745. except for recognizing UTC and GMT which are always known (and are considered to
  746. be non-daylight savings timezones).</p>
  747. <p>Only the directives specified in the documentation are supported. Because
  748. <code class="docutils literal notranslate"><span class="pre">strftime()</span></code> is implemented per platform it can sometimes offer more
  749. directives than those listed. But <code class="docutils literal notranslate"><span class="pre">strptime()</span></code> is independent of any platform
  750. and thus does not necessarily support all directives available that are not
  751. documented as supported.</p>
  752. </dd></dl>
  753. <dl class="py class">
  754. <dt class="sig sig-object py" id="time.struct_time">
  755. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">struct_time</span></span><a class="headerlink" href="#time.struct_time" title="Link to this definition">¶</a></dt>
  756. <dd><p>The type of the time value sequence returned by <a class="reference internal" href="#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a>,
  757. <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a>, and <a class="reference internal" href="#time.strptime" title="time.strptime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strptime()</span></code></a>. It is an object with a <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named
  758. tuple</span></a> interface: values can be accessed by index and by attribute name. The
  759. following values are present:</p>
  760. <table class="docutils align-default">
  761. <tbody>
  762. <tr class="row-odd"><td><p>Index</p></td>
  763. <td><p>Attribute</p></td>
  764. <td><p>Values</p></td>
  765. </tr>
  766. <tr class="row-even"><td><p>0</p></td>
  767. <td><dl class="py attribute">
  768. <dt class="sig sig-object py" id="time.struct_time.tm_year">
  769. <span class="sig-name descname"><span class="pre">tm_year</span></span><a class="headerlink" href="#time.struct_time.tm_year" title="Link to this definition">¶</a></dt>
  770. <dd></dd></dl>
  771. </td>
  772. <td><p>(for example, 1993)</p></td>
  773. </tr>
  774. <tr class="row-odd"><td><p>1</p></td>
  775. <td><dl class="py attribute">
  776. <dt class="sig sig-object py" id="time.struct_time.tm_mon">
  777. <span class="sig-name descname"><span class="pre">tm_mon</span></span><a class="headerlink" href="#time.struct_time.tm_mon" title="Link to this definition">¶</a></dt>
  778. <dd></dd></dl>
  779. </td>
  780. <td><p>range [1, 12]</p></td>
  781. </tr>
  782. <tr class="row-even"><td><p>2</p></td>
  783. <td><dl class="py attribute">
  784. <dt class="sig sig-object py" id="time.struct_time.tm_day">
  785. <span class="sig-name descname"><span class="pre">tm_day</span></span><a class="headerlink" href="#time.struct_time.tm_day" title="Link to this definition">¶</a></dt>
  786. <dd></dd></dl>
  787. </td>
  788. <td><p>range [1, 31]</p></td>
  789. </tr>
  790. <tr class="row-odd"><td><p>3</p></td>
  791. <td><dl class="py attribute">
  792. <dt class="sig sig-object py" id="time.struct_time.tm_hour">
  793. <span class="sig-name descname"><span class="pre">tm_hour</span></span><a class="headerlink" href="#time.struct_time.tm_hour" title="Link to this definition">¶</a></dt>
  794. <dd></dd></dl>
  795. </td>
  796. <td><p>range [0, 23]</p></td>
  797. </tr>
  798. <tr class="row-even"><td><p>4</p></td>
  799. <td><dl class="py attribute">
  800. <dt class="sig sig-object py" id="time.struct_time.tm_min">
  801. <span class="sig-name descname"><span class="pre">tm_min</span></span><a class="headerlink" href="#time.struct_time.tm_min" title="Link to this definition">¶</a></dt>
  802. <dd></dd></dl>
  803. </td>
  804. <td><p>range [0, 59]</p></td>
  805. </tr>
  806. <tr class="row-odd"><td><p>5</p></td>
  807. <td><dl class="py attribute">
  808. <dt class="sig sig-object py" id="time.struct_time.tm_sec">
  809. <span class="sig-name descname"><span class="pre">tm_sec</span></span><a class="headerlink" href="#time.struct_time.tm_sec" title="Link to this definition">¶</a></dt>
  810. <dd></dd></dl>
  811. </td>
  812. <td><p>range [0, 61]; see <a class="reference internal" href="#leap-second"><span class="std std-ref">Note (2)</span></a> in <a class="reference internal" href="#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a></p></td>
  813. </tr>
  814. <tr class="row-even"><td><p>6</p></td>
  815. <td><dl class="py attribute">
  816. <dt class="sig sig-object py" id="time.struct_time.tm_wday">
  817. <span class="sig-name descname"><span class="pre">tm_wday</span></span><a class="headerlink" href="#time.struct_time.tm_wday" title="Link to this definition">¶</a></dt>
  818. <dd></dd></dl>
  819. </td>
  820. <td><p>range [0, 6]; Monday is 0</p></td>
  821. </tr>
  822. <tr class="row-odd"><td><p>7</p></td>
  823. <td><dl class="py attribute">
  824. <dt class="sig sig-object py" id="time.struct_time.tm_yday">
  825. <span class="sig-name descname"><span class="pre">tm_yday</span></span><a class="headerlink" href="#time.struct_time.tm_yday" title="Link to this definition">¶</a></dt>
  826. <dd></dd></dl>
  827. </td>
  828. <td><p>range [1, 366]</p></td>
  829. </tr>
  830. <tr class="row-even"><td><p>8</p></td>
  831. <td><dl class="py attribute">
  832. <dt class="sig sig-object py" id="time.struct_time.tm_isdst">
  833. <span class="sig-name descname"><span class="pre">tm_isdst</span></span><a class="headerlink" href="#time.struct_time.tm_isdst" title="Link to this definition">¶</a></dt>
  834. <dd></dd></dl>
  835. </td>
  836. <td><p>0, 1 or -1; see below</p></td>
  837. </tr>
  838. <tr class="row-odd"><td><p>N/A</p></td>
  839. <td><dl class="py attribute">
  840. <dt class="sig sig-object py" id="time.struct_time.tm_zone">
  841. <span class="sig-name descname"><span class="pre">tm_zone</span></span><a class="headerlink" href="#time.struct_time.tm_zone" title="Link to this definition">¶</a></dt>
  842. <dd></dd></dl>
  843. </td>
  844. <td><p>abbreviation of timezone name</p></td>
  845. </tr>
  846. <tr class="row-even"><td><p>N/A</p></td>
  847. <td><dl class="py attribute">
  848. <dt class="sig sig-object py" id="time.struct_time.tm_gmtoff">
  849. <span class="sig-name descname"><span class="pre">tm_gmtoff</span></span><a class="headerlink" href="#time.struct_time.tm_gmtoff" title="Link to this definition">¶</a></dt>
  850. <dd></dd></dl>
  851. </td>
  852. <td><p>offset east of UTC in seconds</p></td>
  853. </tr>
  854. </tbody>
  855. </table>
  856. <p>Note that unlike the C structure, the month value is a range of [1, 12], not
  857. [0, 11].</p>
  858. <p>In calls to <a class="reference internal" href="#time.mktime" title="time.mktime"><code class="xref py py-func docutils literal notranslate"><span class="pre">mktime()</span></code></a>, <a class="reference internal" href="#time.struct_time.tm_isdst" title="time.struct_time.tm_isdst"><code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_isdst</span></code></a> may be set to 1 when daylight
  859. savings time is in effect, and 0 when it is not. A value of -1 indicates that
  860. this is not known, and will usually result in the correct state being filled in.</p>
  861. <p>When a tuple with an incorrect length is passed to a function expecting a
  862. <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a>, or having elements of the wrong type, a
  863. <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> is raised.</p>
  864. </dd></dl>
  865. <dl class="py function">
  866. <dt class="sig sig-object py" id="time.time">
  867. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">time</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#float" title="float"><span class="pre">float</span></a></span></span><a class="headerlink" href="#time.time" title="Link to this definition">¶</a></dt>
  868. <dd><p>Return the time in seconds since the <a class="reference internal" href="#epoch">epoch</a> as a floating point
  869. number. The handling of <a class="reference external" href="https://en.wikipedia.org/wiki/Leap_second">leap seconds</a> is platform dependent.
  870. On Windows and most Unix systems, the leap seconds are not counted towards
  871. the time in seconds since the <a class="reference internal" href="#epoch">epoch</a>. This is commonly referred to as <a class="reference external" href="https://en.wikipedia.org/wiki/Unix_time">Unix
  872. time</a>.</p>
  873. <p>Note that even though the time is always returned as a floating point
  874. number, not all systems provide time with a better precision than 1 second.
  875. While this function normally returns non-decreasing values, it can return a
  876. lower value than a previous call if the system clock has been set back
  877. between the two calls.</p>
  878. <p>The number returned by <a class="reference internal" href="#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time()</span></code></a> may be converted into a more common
  879. time format (i.e. year, month, day, hour, etc…) in UTC by passing it to
  880. <a class="reference internal" href="#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a> function or in local time by passing it to the
  881. <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a> function. In both cases a
  882. <a class="reference internal" href="#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> object is returned, from which the components
  883. of the calendar date may be accessed as attributes.</p>
  884. <p>Use <a class="reference internal" href="#time.time_ns" title="time.time_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time_ns()</span></code></a> to avoid the precision loss caused by the <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>
  885. type.</p>
  886. </dd></dl>
  887. <dl class="py function">
  888. <dt class="sig sig-object py" id="time.time_ns">
  889. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">time_ns</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#int" title="int"><span class="pre">int</span></a></span></span><a class="headerlink" href="#time.time_ns" title="Link to this definition">¶</a></dt>
  890. <dd><p>Similar to <a class="reference internal" href="#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time()</span></code></a> but returns time as an integer number of
  891. nanoseconds since the <a class="reference internal" href="#epoch">epoch</a>.</p>
  892. <div class="versionadded">
  893. <p><span class="versionmodified added">New in version 3.7.</span></p>
  894. </div>
  895. </dd></dl>
  896. <dl class="py function">
  897. <dt class="sig sig-object py" id="time.thread_time">
  898. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">thread_time</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#float" title="float"><span class="pre">float</span></a></span></span><a class="headerlink" href="#time.thread_time" title="Link to this definition">¶</a></dt>
  899. <dd><p id="index-12">Return the value (in fractional seconds) of the sum of the system and user
  900. CPU time of the current thread. It does not include time elapsed during
  901. sleep. It is thread-specific by definition. The reference point of the
  902. returned value is undefined, so that only the difference between the results
  903. of two calls in the same thread is valid.</p>
  904. <p>Use <a class="reference internal" href="#time.thread_time_ns" title="time.thread_time_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">thread_time_ns()</span></code></a> to avoid the precision loss caused by the
  905. <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> type.</p>
  906. <div class="availability docutils container">
  907. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux, Unix, Windows.</p>
  908. <p>Unix systems supporting <code class="docutils literal notranslate"><span class="pre">CLOCK_THREAD_CPUTIME_ID</span></code>.</p>
  909. </div>
  910. <div class="versionadded">
  911. <p><span class="versionmodified added">New in version 3.7.</span></p>
  912. </div>
  913. </dd></dl>
  914. <dl class="py function">
  915. <dt class="sig sig-object py" id="time.thread_time_ns">
  916. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">thread_time_ns</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="functions.html#int" title="int"><span class="pre">int</span></a></span></span><a class="headerlink" href="#time.thread_time_ns" title="Link to this definition">¶</a></dt>
  917. <dd><p>Similar to <a class="reference internal" href="#time.thread_time" title="time.thread_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">thread_time()</span></code></a> but return time as nanoseconds.</p>
  918. <div class="versionadded">
  919. <p><span class="versionmodified added">New in version 3.7.</span></p>
  920. </div>
  921. </dd></dl>
  922. <dl class="py function">
  923. <dt class="sig sig-object py" id="time.tzset">
  924. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">tzset</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#time.tzset" title="Link to this definition">¶</a></dt>
  925. <dd><p>Reset the time conversion rules used by the library routines. The environment
  926. variable <span class="target" id="index-13"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">TZ</span></code> specifies how this is done. It will also set the variables
  927. <code class="docutils literal notranslate"><span class="pre">tzname</span></code> (from the <span class="target" id="index-14"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">TZ</span></code> environment variable), <code class="docutils literal notranslate"><span class="pre">timezone</span></code> (non-DST
  928. seconds West of UTC), <code class="docutils literal notranslate"><span class="pre">altzone</span></code> (DST seconds west of UTC) and <code class="docutils literal notranslate"><span class="pre">daylight</span></code>
  929. (to 0 if this timezone does not have any daylight saving time rules, or to
  930. nonzero if there is a time, past, present or future when daylight saving time
  931. applies).</p>
  932. <div class="availability docutils container">
  933. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  934. </div>
  935. <div class="admonition note">
  936. <p class="admonition-title">Note</p>
  937. <p>Although in many cases, changing the <span class="target" id="index-15"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">TZ</span></code> environment variable may
  938. affect the output of functions like <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a> without calling
  939. <a class="reference internal" href="#time.tzset" title="time.tzset"><code class="xref py py-func docutils literal notranslate"><span class="pre">tzset()</span></code></a>, this behavior should not be relied on.</p>
  940. <p>The <span class="target" id="index-16"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">TZ</span></code> environment variable should contain no whitespace.</p>
  941. </div>
  942. <p>The standard format of the <span class="target" id="index-17"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">TZ</span></code> environment variable is (whitespace
  943. added for clarity):</p>
  944. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">std</span> <span class="n">offset</span> <span class="p">[</span><span class="n">dst</span> <span class="p">[</span><span class="n">offset</span> <span class="p">[,</span><span class="n">start</span><span class="p">[</span><span class="o">/</span><span class="n">time</span><span class="p">],</span> <span class="n">end</span><span class="p">[</span><span class="o">/</span><span class="n">time</span><span class="p">]]]]</span>
  945. </pre></div>
  946. </div>
  947. <p>Where the components are:</p>
  948. <dl>
  949. <dt><code class="docutils literal notranslate"><span class="pre">std</span></code> and <code class="docutils literal notranslate"><span class="pre">dst</span></code></dt><dd><p>Three or more alphanumerics giving the timezone abbreviations. These will be
  950. propagated into time.tzname</p>
  951. </dd>
  952. <dt><code class="docutils literal notranslate"><span class="pre">offset</span></code></dt><dd><p>The offset has the form: <code class="docutils literal notranslate"><span class="pre">±</span> <span class="pre">hh[:mm[:ss]]</span></code>. This indicates the value
  953. added the local time to arrive at UTC. If preceded by a ‘-’, the timezone
  954. is east of the Prime Meridian; otherwise, it is west. If no offset follows
  955. dst, summer time is assumed to be one hour ahead of standard time.</p>
  956. </dd>
  957. <dt><code class="docutils literal notranslate"><span class="pre">start[/time],</span> <span class="pre">end[/time]</span></code></dt><dd><p>Indicates when to change to and back from DST. The format of the
  958. start and end dates are one of the following:</p>
  959. <dl class="simple">
  960. <dt><code class="samp docutils literal notranslate"><span class="pre">J</span><em><span class="pre">n</span></em></code></dt><dd><p>The Julian day <em>n</em> (1 &lt;= <em>n</em> &lt;= 365). Leap days are not counted, so in
  961. all years February 28 is day 59 and March 1 is day 60.</p>
  962. </dd>
  963. <dt><code class="samp docutils literal notranslate"><em><span class="pre">n</span></em></code></dt><dd><p>The zero-based Julian day (0 &lt;= <em>n</em> &lt;= 365). Leap days are counted, and
  964. it is possible to refer to February 29.</p>
  965. </dd>
  966. <dt><code class="samp docutils literal notranslate"><span class="pre">M</span><em><span class="pre">m</span></em><span class="pre">.</span><em><span class="pre">n</span></em><span class="pre">.</span><em><span class="pre">d</span></em></code></dt><dd><p>The <em>d</em>’th day (0 &lt;= <em>d</em> &lt;= 6) of week <em>n</em> of month <em>m</em> of the year (1
  967. &lt;= <em>n</em> &lt;= 5, 1 &lt;= <em>m</em> &lt;= 12, where week 5 means “the last <em>d</em> day in
  968. month <em>m</em>” which may occur in either the fourth or the fifth
  969. week). Week 1 is the first week in which the <em>d</em>’th day occurs. Day
  970. zero is a Sunday.</p>
  971. </dd>
  972. </dl>
  973. <p><code class="docutils literal notranslate"><span class="pre">time</span></code> has the same format as <code class="docutils literal notranslate"><span class="pre">offset</span></code> except that no leading sign
  974. (‘-’ or ‘+’) is allowed. The default, if time is not given, is 02:00:00.</p>
  975. </dd>
  976. </dl>
  977. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;TZ&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;EST+05EDT,M4.1.0,M10.5.0&#39;</span>
  978. <span class="gp">&gt;&gt;&gt; </span><span class="n">time</span><span class="o">.</span><span class="n">tzset</span><span class="p">()</span>
  979. <span class="gp">&gt;&gt;&gt; </span><span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%X</span><span class="s1"> </span><span class="si">%x</span><span class="s1"> %Z&#39;</span><span class="p">)</span>
  980. <span class="go">&#39;02:07:36 05/08/03 EDT&#39;</span>
  981. <span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;TZ&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;AEST-10AEDT-11,M10.5.0,M3.5.0&#39;</span>
  982. <span class="gp">&gt;&gt;&gt; </span><span class="n">time</span><span class="o">.</span><span class="n">tzset</span><span class="p">()</span>
  983. <span class="gp">&gt;&gt;&gt; </span><span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%X</span><span class="s1"> </span><span class="si">%x</span><span class="s1"> %Z&#39;</span><span class="p">)</span>
  984. <span class="go">&#39;16:08:12 05/08/03 AEST&#39;</span>
  985. </pre></div>
  986. </div>
  987. <p>On many Unix systems (including *BSD, Linux, Solaris, and Darwin), it is more
  988. convenient to use the system’s zoneinfo (<em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/tzfile(5)">tzfile(5)</a></em>) database to
  989. specify the timezone rules. To do this, set the <span class="target" id="index-18"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">TZ</span></code> environment
  990. variable to the path of the required timezone datafile, relative to the root of
  991. the systems ‘zoneinfo’ timezone database, usually located at
  992. <code class="file docutils literal notranslate"><span class="pre">/usr/share/zoneinfo</span></code>. For example, <code class="docutils literal notranslate"><span class="pre">'US/Eastern'</span></code>,
  993. <code class="docutils literal notranslate"><span class="pre">'Australia/Melbourne'</span></code>, <code class="docutils literal notranslate"><span class="pre">'Egypt'</span></code> or <code class="docutils literal notranslate"><span class="pre">'Europe/Amsterdam'</span></code>.</p>
  994. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;TZ&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;US/Eastern&#39;</span>
  995. <span class="gp">&gt;&gt;&gt; </span><span class="n">time</span><span class="o">.</span><span class="n">tzset</span><span class="p">()</span>
  996. <span class="gp">&gt;&gt;&gt; </span><span class="n">time</span><span class="o">.</span><span class="n">tzname</span>
  997. <span class="go">(&#39;EST&#39;, &#39;EDT&#39;)</span>
  998. <span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;TZ&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;Egypt&#39;</span>
  999. <span class="gp">&gt;&gt;&gt; </span><span class="n">time</span><span class="o">.</span><span class="n">tzset</span><span class="p">()</span>
  1000. <span class="gp">&gt;&gt;&gt; </span><span class="n">time</span><span class="o">.</span><span class="n">tzname</span>
  1001. <span class="go">(&#39;EET&#39;, &#39;EEST&#39;)</span>
  1002. </pre></div>
  1003. </div>
  1004. </dd></dl>
  1005. </section>
  1006. <section id="clock-id-constants">
  1007. <span id="time-clock-id-constants"></span><h2>Clock ID Constants<a class="headerlink" href="#clock-id-constants" title="Link to this heading">¶</a></h2>
  1008. <p>These constants are used as parameters for <a class="reference internal" href="#time.clock_getres" title="time.clock_getres"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_getres()</span></code></a> and
  1009. <a class="reference internal" href="#time.clock_gettime" title="time.clock_gettime"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_gettime()</span></code></a>.</p>
  1010. <dl class="py data">
  1011. <dt class="sig sig-object py" id="time.CLOCK_BOOTTIME">
  1012. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_BOOTTIME</span></span><a class="headerlink" href="#time.CLOCK_BOOTTIME" title="Link to this definition">¶</a></dt>
  1013. <dd><p>Identical to <a class="reference internal" href="#time.CLOCK_MONOTONIC" title="time.CLOCK_MONOTONIC"><code class="xref py py-data docutils literal notranslate"><span class="pre">CLOCK_MONOTONIC</span></code></a>, except it also includes any time that
  1014. the system is suspended.</p>
  1015. <p>This allows applications to get a suspend-aware monotonic clock without
  1016. having to deal with the complications of <a class="reference internal" href="#time.CLOCK_REALTIME" title="time.CLOCK_REALTIME"><code class="xref py py-data docutils literal notranslate"><span class="pre">CLOCK_REALTIME</span></code></a>, which may
  1017. have discontinuities if the time is changed using <code class="docutils literal notranslate"><span class="pre">settimeofday()</span></code> or
  1018. similar.</p>
  1019. <div class="availability docutils container">
  1020. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux &gt;= 2.6.39.</p>
  1021. </div>
  1022. <div class="versionadded">
  1023. <p><span class="versionmodified added">New in version 3.7.</span></p>
  1024. </div>
  1025. </dd></dl>
  1026. <dl class="py data">
  1027. <dt class="sig sig-object py" id="time.CLOCK_HIGHRES">
  1028. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_HIGHRES</span></span><a class="headerlink" href="#time.CLOCK_HIGHRES" title="Link to this definition">¶</a></dt>
  1029. <dd><p>The Solaris OS has a <code class="docutils literal notranslate"><span class="pre">CLOCK_HIGHRES</span></code> timer that attempts to use an optimal
  1030. hardware source, and may give close to nanosecond resolution.
  1031. <code class="docutils literal notranslate"><span class="pre">CLOCK_HIGHRES</span></code> is the nonadjustable, high-resolution clock.</p>
  1032. <div class="availability docutils container">
  1033. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Solaris.</p>
  1034. </div>
  1035. <div class="versionadded">
  1036. <p><span class="versionmodified added">New in version 3.3.</span></p>
  1037. </div>
  1038. </dd></dl>
  1039. <dl class="py data">
  1040. <dt class="sig sig-object py" id="time.CLOCK_MONOTONIC">
  1041. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_MONOTONIC</span></span><a class="headerlink" href="#time.CLOCK_MONOTONIC" title="Link to this definition">¶</a></dt>
  1042. <dd><p>Clock that cannot be set and represents monotonic time since some unspecified
  1043. starting point.</p>
  1044. <div class="availability docutils container">
  1045. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  1046. </div>
  1047. <div class="versionadded">
  1048. <p><span class="versionmodified added">New in version 3.3.</span></p>
  1049. </div>
  1050. </dd></dl>
  1051. <dl class="py data">
  1052. <dt class="sig sig-object py" id="time.CLOCK_MONOTONIC_RAW">
  1053. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_MONOTONIC_RAW</span></span><a class="headerlink" href="#time.CLOCK_MONOTONIC_RAW" title="Link to this definition">¶</a></dt>
  1054. <dd><p>Similar to <a class="reference internal" href="#time.CLOCK_MONOTONIC" title="time.CLOCK_MONOTONIC"><code class="xref py py-data docutils literal notranslate"><span class="pre">CLOCK_MONOTONIC</span></code></a>, but provides access to a raw
  1055. hardware-based time that is not subject to NTP adjustments.</p>
  1056. <div class="availability docutils container">
  1057. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux &gt;= 2.6.28, macOS &gt;= 10.12.</p>
  1058. </div>
  1059. <div class="versionadded">
  1060. <p><span class="versionmodified added">New in version 3.3.</span></p>
  1061. </div>
  1062. </dd></dl>
  1063. <dl class="py data">
  1064. <dt class="sig sig-object py" id="time.CLOCK_PROCESS_CPUTIME_ID">
  1065. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_PROCESS_CPUTIME_ID</span></span><a class="headerlink" href="#time.CLOCK_PROCESS_CPUTIME_ID" title="Link to this definition">¶</a></dt>
  1066. <dd><p>High-resolution per-process timer from the CPU.</p>
  1067. <div class="availability docutils container">
  1068. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  1069. </div>
  1070. <div class="versionadded">
  1071. <p><span class="versionmodified added">New in version 3.3.</span></p>
  1072. </div>
  1073. </dd></dl>
  1074. <dl class="py data">
  1075. <dt class="sig sig-object py" id="time.CLOCK_PROF">
  1076. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_PROF</span></span><a class="headerlink" href="#time.CLOCK_PROF" title="Link to this definition">¶</a></dt>
  1077. <dd><p>High-resolution per-process timer from the CPU.</p>
  1078. <div class="availability docutils container">
  1079. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD, NetBSD &gt;= 7, OpenBSD.</p>
  1080. </div>
  1081. <div class="versionadded">
  1082. <p><span class="versionmodified added">New in version 3.7.</span></p>
  1083. </div>
  1084. </dd></dl>
  1085. <dl class="py data">
  1086. <dt class="sig sig-object py" id="time.CLOCK_TAI">
  1087. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_TAI</span></span><a class="headerlink" href="#time.CLOCK_TAI" title="Link to this definition">¶</a></dt>
  1088. <dd><p><a class="reference external" href="https://www.nist.gov/pml/time-and-frequency-division/nist-time-frequently-asked-questions-faq#tai">International Atomic Time</a></p>
  1089. <p>The system must have a current leap second table in order for this to give
  1090. the correct answer. PTP or NTP software can maintain a leap second table.</p>
  1091. <div class="availability docutils container">
  1092. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Linux.</p>
  1093. </div>
  1094. <div class="versionadded">
  1095. <p><span class="versionmodified added">New in version 3.9.</span></p>
  1096. </div>
  1097. </dd></dl>
  1098. <dl class="py data">
  1099. <dt class="sig sig-object py" id="time.CLOCK_THREAD_CPUTIME_ID">
  1100. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_THREAD_CPUTIME_ID</span></span><a class="headerlink" href="#time.CLOCK_THREAD_CPUTIME_ID" title="Link to this definition">¶</a></dt>
  1101. <dd><p>Thread-specific CPU-time clock.</p>
  1102. <div class="availability docutils container">
  1103. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  1104. </div>
  1105. <div class="versionadded">
  1106. <p><span class="versionmodified added">New in version 3.3.</span></p>
  1107. </div>
  1108. </dd></dl>
  1109. <dl class="py data">
  1110. <dt class="sig sig-object py" id="time.CLOCK_UPTIME">
  1111. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_UPTIME</span></span><a class="headerlink" href="#time.CLOCK_UPTIME" title="Link to this definition">¶</a></dt>
  1112. <dd><p>Time whose absolute value is the time the system has been running and not
  1113. suspended, providing accurate uptime measurement, both absolute and
  1114. interval.</p>
  1115. <div class="availability docutils container">
  1116. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: FreeBSD, OpenBSD &gt;= 5.5.</p>
  1117. </div>
  1118. <div class="versionadded">
  1119. <p><span class="versionmodified added">New in version 3.7.</span></p>
  1120. </div>
  1121. </dd></dl>
  1122. <dl class="py data">
  1123. <dt class="sig sig-object py" id="time.CLOCK_UPTIME_RAW">
  1124. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_UPTIME_RAW</span></span><a class="headerlink" href="#time.CLOCK_UPTIME_RAW" title="Link to this definition">¶</a></dt>
  1125. <dd><p>Clock that increments monotonically, tracking the time since an arbitrary
  1126. point, unaffected by frequency or time adjustments and not incremented while
  1127. the system is asleep.</p>
  1128. <div class="availability docutils container">
  1129. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: macOS &gt;= 10.12.</p>
  1130. </div>
  1131. <div class="versionadded">
  1132. <p><span class="versionmodified added">New in version 3.8.</span></p>
  1133. </div>
  1134. </dd></dl>
  1135. <p>The following constant is the only parameter that can be sent to
  1136. <a class="reference internal" href="#time.clock_settime" title="time.clock_settime"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_settime()</span></code></a>.</p>
  1137. <dl class="py data">
  1138. <dt class="sig sig-object py" id="time.CLOCK_REALTIME">
  1139. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">CLOCK_REALTIME</span></span><a class="headerlink" href="#time.CLOCK_REALTIME" title="Link to this definition">¶</a></dt>
  1140. <dd><p>System-wide real-time clock. Setting this clock requires appropriate
  1141. privileges.</p>
  1142. <div class="availability docutils container">
  1143. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>
  1144. </div>
  1145. <div class="versionadded">
  1146. <p><span class="versionmodified added">New in version 3.3.</span></p>
  1147. </div>
  1148. </dd></dl>
  1149. </section>
  1150. <section id="timezone-constants">
  1151. <span id="time-timezone-constants"></span><h2>Timezone Constants<a class="headerlink" href="#timezone-constants" title="Link to this heading">¶</a></h2>
  1152. <dl class="py data">
  1153. <dt class="sig sig-object py" id="time.altzone">
  1154. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">altzone</span></span><a class="headerlink" href="#time.altzone" title="Link to this definition">¶</a></dt>
  1155. <dd><p>The offset of the local DST timezone, in seconds west of UTC, if one is defined.
  1156. This is negative if the local DST timezone is east of UTC (as in Western Europe,
  1157. including the UK). Only use this if <code class="docutils literal notranslate"><span class="pre">daylight</span></code> is nonzero. See note below.</p>
  1158. </dd></dl>
  1159. <dl class="py data">
  1160. <dt class="sig sig-object py" id="time.daylight">
  1161. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">daylight</span></span><a class="headerlink" href="#time.daylight" title="Link to this definition">¶</a></dt>
  1162. <dd><p>Nonzero if a DST timezone is defined. See note below.</p>
  1163. </dd></dl>
  1164. <dl class="py data">
  1165. <dt class="sig sig-object py" id="time.timezone">
  1166. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">timezone</span></span><a class="headerlink" href="#time.timezone" title="Link to this definition">¶</a></dt>
  1167. <dd><p>The offset of the local (non-DST) timezone, in seconds west of UTC (negative in
  1168. most of Western Europe, positive in the US, zero in the UK). See note below.</p>
  1169. </dd></dl>
  1170. <dl class="py data">
  1171. <dt class="sig sig-object py" id="time.tzname">
  1172. <span class="sig-prename descclassname"><span class="pre">time.</span></span><span class="sig-name descname"><span class="pre">tzname</span></span><a class="headerlink" href="#time.tzname" title="Link to this definition">¶</a></dt>
  1173. <dd><p>A tuple of two strings: the first is the name of the local non-DST timezone, the
  1174. second is the name of the local DST timezone. If no DST timezone is defined,
  1175. the second string should not be used. See note below.</p>
  1176. </dd></dl>
  1177. <div class="admonition note">
  1178. <p class="admonition-title">Note</p>
  1179. <p>For the above Timezone constants (<a class="reference internal" href="#time.altzone" title="time.altzone"><code class="xref py py-data docutils literal notranslate"><span class="pre">altzone</span></code></a>, <a class="reference internal" href="#time.daylight" title="time.daylight"><code class="xref py py-data docutils literal notranslate"><span class="pre">daylight</span></code></a>, <a class="reference internal" href="#time.timezone" title="time.timezone"><code class="xref py py-data docutils literal notranslate"><span class="pre">timezone</span></code></a>,
  1180. and <a class="reference internal" href="#time.tzname" title="time.tzname"><code class="xref py py-data docutils literal notranslate"><span class="pre">tzname</span></code></a>), the value is determined by the timezone rules in effect
  1181. at module load time or the last time <a class="reference internal" href="#time.tzset" title="time.tzset"><code class="xref py py-func docutils literal notranslate"><span class="pre">tzset()</span></code></a> is called and may be incorrect
  1182. for times in the past. It is recommended to use the <a class="reference internal" href="#time.struct_time.tm_gmtoff" title="time.struct_time.tm_gmtoff"><code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_gmtoff</span></code></a> and
  1183. <a class="reference internal" href="#time.struct_time.tm_zone" title="time.struct_time.tm_zone"><code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_zone</span></code></a> results from <a class="reference internal" href="#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a> to obtain timezone information.</p>
  1184. </div>
  1185. <div class="admonition seealso">
  1186. <p class="admonition-title">See also</p>
  1187. <dl class="simple">
  1188. <dt>Module <a class="reference internal" href="datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a></dt><dd><p>More object-oriented interface to dates and times.</p>
  1189. </dd>
  1190. <dt>Module <a class="reference internal" href="locale.html#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a></dt><dd><p>Internationalization services. The locale setting affects the interpretation
  1191. of many format specifiers in <a class="reference internal" href="#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strftime()</span></code></a> and <a class="reference internal" href="#time.strptime" title="time.strptime"><code class="xref py py-func docutils literal notranslate"><span class="pre">strptime()</span></code></a>.</p>
  1192. </dd>
  1193. <dt>Module <a class="reference internal" href="calendar.html#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code></a></dt><dd><p>General calendar-related functions. <a class="reference internal" href="calendar.html#calendar.timegm" title="calendar.timegm"><code class="xref py py-func docutils literal notranslate"><span class="pre">timegm()</span></code></a> is the
  1194. inverse of <a class="reference internal" href="#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">gmtime()</span></code></a> from this module.</p>
  1195. </dd>
  1196. </dl>
  1197. </div>
  1198. <p class="rubric">Footnotes</p>
  1199. <aside class="footnote-list brackets">
  1200. <aside class="footnote brackets" id="id4" role="doc-footnote">
  1201. <span class="label"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></span>
  1202. <span class="backrefs">(<a role="doc-backlink" href="#id1">1</a>,<a role="doc-backlink" href="#id2">2</a>,<a role="doc-backlink" href="#id3">3</a>)</span>
  1203. <p>The use of <code class="docutils literal notranslate"><span class="pre">%Z</span></code> is now deprecated, but the <code class="docutils literal notranslate"><span class="pre">%z</span></code> escape that expands to the
  1204. preferred hour/minute offset is not supported by all ANSI C libraries. Also, a
  1205. strict reading of the original 1982 <span class="target" id="index-19"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc822.html"><strong>RFC 822</strong></a> standard calls for a two-digit
  1206. year (<code class="docutils literal notranslate"><span class="pre">%y</span></code> rather than <code class="docutils literal notranslate"><span class="pre">%Y</span></code>), but practice moved to 4-digit years long before the
  1207. year 2000. After that, <span class="target" id="index-20"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc822.html"><strong>RFC 822</strong></a> became obsolete and the 4-digit year has
  1208. been first recommended by <span class="target" id="index-21"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1123.html"><strong>RFC 1123</strong></a> and then mandated by <span class="target" id="index-22"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2822.html"><strong>RFC 2822</strong></a>.</p>
  1209. </aside>
  1210. </aside>
  1211. </section>
  1212. </section>
  1213. <div class="clearer"></div>
  1214. </div>
  1215. </div>
  1216. </div>
  1217. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  1218. <div class="sphinxsidebarwrapper">
  1219. <div>
  1220. <h3><a href="../contents.html">Table of Contents</a></h3>
  1221. <ul>
  1222. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code> — Time access and conversions</a><ul>
  1223. <li><a class="reference internal" href="#functions">Functions</a></li>
  1224. <li><a class="reference internal" href="#clock-id-constants">Clock ID Constants</a></li>
  1225. <li><a class="reference internal" href="#timezone-constants">Timezone Constants</a></li>
  1226. </ul>
  1227. </li>
  1228. </ul>
  1229. </div>
  1230. <div>
  1231. <h4>Previous topic</h4>
  1232. <p class="topless"><a href="io.html"
  1233. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code> — Core tools for working with streams</a></p>
  1234. </div>
  1235. <div>
  1236. <h4>Next topic</h4>
  1237. <p class="topless"><a href="argparse.html"
  1238. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code> — Parser for command-line options, arguments and sub-commands</a></p>
  1239. </div>
  1240. <div role="note" aria-label="source link">
  1241. <h3>This Page</h3>
  1242. <ul class="this-page-menu">
  1243. <li><a href="../bugs.html">Report a Bug</a></li>
  1244. <li>
  1245. <a href="https://github.com/python/cpython/blob/main/Doc/library/time.rst"
  1246. rel="nofollow">Show Source
  1247. </a>
  1248. </li>
  1249. </ul>
  1250. </div>
  1251. </div>
  1252. <div id="sidebarbutton" title="Collapse sidebar">
  1253. <span>«</span>
  1254. </div>
  1255. </div>
  1256. <div class="clearer"></div>
  1257. </div>
  1258. <div class="related" role="navigation" aria-label="related navigation">
  1259. <h3>Navigation</h3>
  1260. <ul>
  1261. <li class="right" style="margin-right: 10px">
  1262. <a href="../genindex.html" title="General Index"
  1263. >index</a></li>
  1264. <li class="right" >
  1265. <a href="../py-modindex.html" title="Python Module Index"
  1266. >modules</a> |</li>
  1267. <li class="right" >
  1268. <a href="argparse.html" title="argparse — Parser for command-line options, arguments and sub-commands"
  1269. >next</a> |</li>
  1270. <li class="right" >
  1271. <a href="io.html" title="io — Core tools for working with streams"
  1272. >previous</a> |</li>
  1273. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  1274. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  1275. <li class="switchers">
  1276. <div class="language_switcher_placeholder"></div>
  1277. <div class="version_switcher_placeholder"></div>
  1278. </li>
  1279. <li>
  1280. </li>
  1281. <li id="cpython-language-and-version">
  1282. <a href="../index.html">3.12.3 Documentation</a> &#187;
  1283. </li>
  1284. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  1285. <li class="nav-item nav-item-2"><a href="allos.html" >Generic Operating System Services</a> &#187;</li>
  1286. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code> — Time access and conversions</a></li>
  1287. <li class="right">
  1288. <div class="inline-search" role="search">
  1289. <form class="inline-search" action="../search.html" method="get">
  1290. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  1291. <input type="submit" value="Go" />
  1292. </form>
  1293. </div>
  1294. |
  1295. </li>
  1296. <li class="right">
  1297. <label class="theme-selector-label">
  1298. Theme
  1299. <select class="theme-selector" oninput="activateTheme(this.value)">
  1300. <option value="auto" selected>Auto</option>
  1301. <option value="light">Light</option>
  1302. <option value="dark">Dark</option>
  1303. </select>
  1304. </label> |</li>
  1305. </ul>
  1306. </div>
  1307. <div class="footer">
  1308. &copy;
  1309. <a href="../copyright.html">
  1310. Copyright
  1311. </a>
  1312. 2001-2024, Python Software Foundation.
  1313. <br />
  1314. This page is licensed under the Python Software Foundation License Version 2.
  1315. <br />
  1316. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  1317. <br />
  1318. See <a href="/license.html">History and License</a> for more information.<br />
  1319. <br />
  1320. The Python Software Foundation is a non-profit corporation.
  1321. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  1322. <br />
  1323. <br />
  1324. Last updated on Apr 09, 2024 (13:47 UTC).
  1325. <a href="/bugs.html">Found a bug</a>?
  1326. <br />
  1327. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  1328. </div>
  1329. </body>
  1330. </html>
上海开阖软件有限公司 沪ICP备12045867号-1