home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / t / time < prev    next >
Encoding:
Text File  |  1996-11-14  |  8.6 KB  |  180 lines

  1. <TITLE>time -- Python library reference</TITLE>
  2. Next: <A HREF="../g/getopt" TYPE="Next">getopt</A>  
  3. Prev: <A HREF="../o/os" TYPE="Prev">os</A>  
  4. Up: <A HREF="../g/generic_operating_system_services" TYPE="Up">Generic Operating System Services</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H1>6.2. Built-in Module <CODE>time</CODE></H1>
  7. This module provides various time-related functions.
  8. It is always available.
  9. <P>
  10. An explanation of some terminology and conventions is in order.
  11. <P>
  12. <UL>
  13. <LI>•  The ``epoch'' is the point where the time starts.  On January 1st of that
  14. year, at 0 hours, the ``time since the epoch'' is zero.  For UNIX, the
  15. epoch is 1970.  To find out what the epoch is, look at <CODE>gmtime(0)</CODE>.
  16. <P>
  17. <LI>•  UTC is Coordinated Universal Time (formerly known as Greenwich Mean
  18. Time).  The acronym UTC is not a mistake but a compromise between
  19. English and French.
  20. <P>
  21. <LI>•  DST is Daylight Saving Time, an adjustment of the timezone by
  22. (usually) one hour during part of the year.  DST rules are magic
  23. (determined by local law) and can change from year to year.  The C
  24. library has a table containing the local rules (often it is read from
  25. a system file for flexibility) and is the only source of True Wisdom
  26. in this respect.
  27. <P>
  28. <LI>•  The precision of the various real-time functions may be less than
  29. suggested by the units in which their value or argument is expressed.
  30. E.g. on most UNIX systems, the clock ``ticks'' only 50 or 100 times a
  31. second, and on the Mac, times are only accurate to whole seconds.
  32. <P>
  33. <LI>•  The time tuple as returned by <CODE>gmtime()</CODE> and <CODE>localtime()</CODE>,
  34. or as accpted by <CODE>mktime()</CODE> is a tuple of 9
  35. integers: year (e.g. 1993), month (1--12), day (1--31), hour
  36. (0--23), minute (0--59), second (0--59), weekday (0--6, monday is 0),
  37. Julian day (1--366) and daylight savings flag (-1, 0  or 1).
  38. Note that unlike the C structure, the month value is a range of 1-12, not
  39. 0-11.  A year value of  100 will typically be silently converted to
  40. 1900  year value.  A -1 argument as daylight savings flag, passed to
  41. <CODE>mktime()</CODE> will usually result in the correct daylight savings
  42. state to be filled in.
  43. <P>
  44. </UL>
  45. The module defines the following functions and data items:
  46. <P>
  47. <DL><DT><B>altzone</B> -- data of module time<DD>
  48. The offset of the local DST timezone, in seconds west of the 0th
  49. meridian, if one is defined.  Negative if the local DST timezone is
  50. east of the 0th meridian (as in Western Europe, including the UK).
  51. Only use this if <CODE>daylight</CODE> is nonzero.
  52. </DL>
  53. <DL><DT><B>asctime</B> (<VAR>tuple</VAR>) -- function of module time<DD>
  54. Convert a tuple representing a time as returned by <CODE>gmtime()</CODE> or
  55. <CODE>localtime()</CODE> to a 24-character string of the following form:
  56. <CODE>'Sun Jun 20 23:21:05 1993'</CODE>.  Note: unlike the C function of
  57. the same name, there is no trailing newline.
  58. </DL>
  59. <DL><DT><B>clock</B> () -- function of module time<DD>
  60. Return the current CPU time as a floating point number expressed in
  61. seconds.  The precision, and in fact the very definiton of the meaning
  62. of ``CPU time'', depends on that of the C function of the same name.
  63. </DL>
  64. <DL><DT><B>ctime</B> (<VAR>secs</VAR>) -- function of module time<DD>
  65. Convert a time expressed in seconds since the epoch to a string
  66. representing local time.  <CODE>ctime(t)</CODE> is equivalent to
  67. <CODE>asctime(localtime(t))</CODE>.
  68. </DL>
  69. <DL><DT><B>daylight</B> -- data of module time<DD>
  70. Nonzero if a DST timezone is defined.
  71. </DL>
  72. <DL><DT><B>gmtime</B> (<VAR>secs</VAR>) -- function of module time<DD>
  73. Convert a time expressed in seconds since the epoch to a time tuple
  74. in UTC in which the dst flag is always zero.  Fractions of a second are
  75. ignored.
  76. </DL>
  77. <DL><DT><B>localtime</B> (<VAR>secs</VAR>) -- function of module time<DD>
  78. Like <CODE>gmtime</CODE> but converts to local time.  The dst flag is set
  79. to 1 when DST applies to the given time.
  80. </DL>
  81. <DL><DT><B>mktime</B> (<VAR>tuple</VAR>) -- function of module time<DD>
  82. This is the inverse function of <CODE>localtime</CODE>.  Its argument is the
  83. full 9-tuple (since the dst flag is needed --- pass -1 as the dst flag if
  84. it is unknown) which expresses the time
  85. in @em{local} time, not UTC.  It returns a floating
  86. point number, for compatibility with <CODE>time.time()</CODE>.  If the input
  87. value can't be represented as a valid time, OverflowError is raised.
  88. </DL>
  89. <DL><DT><B>sleep</B> (<VAR>secs</VAR>) -- function of module time<DD>
  90. Suspend execution for the given number of seconds.  The argument may
  91. be a floating point number to indicate a more precise sleep time.
  92. </DL>
  93. <DL><DT><B>strftime</B> (<VAR>format</VAR>, <VAR>tuple</VAR>) -- function of module time<DD>
  94. Convert a tuple representing a time as returned by <CODE>gmtime()</CODE> or
  95. <CODE>localtime()</CODE> to a string as specified by the format argument.
  96. <P>
  97. The following directives, shown without the optional field width and
  98. precision specification, are replaced by the indicated characters:
  99. <P>
  100. lp25em
  101. %a  &      Locale's abbreviated weekday name. *
  102. %A  &      Locale's full weekday name. *
  103. %b  &      Locale's abbreviated month name. *
  104. %B  &      Locale's full month name. *
  105. %c  &      Locale's appropriate date and time representation. *
  106. %d  &      Day of the month as a decimal number [01,31]. *
  107. %E  &      Locale's combined Emperor/Era name and year. *
  108. %H  &      Hour (24-hour clock) as a decimal number [00,23]. *
  109. %I  &      Hour (12-hour clock) as a decimal number [01,12]. *
  110. %j  &      Day of the year as a decimal number [001,366]. *
  111. %m  &      Month as a decimal number [01,12]. *
  112. %M  &      Minute as a decimal number [00,59]. *
  113. %n  &      New-line character. *
  114. %N  &      Locale's Emperor/Era name. *
  115. %o  &      Locale's Emperor/Era year. *
  116. %p  &      Locale's equivalent of either AM or PM. *
  117. %S  &      Second as a decimal number [00,61]. *
  118. %t  &      Tab character. *
  119. %U  &      Week number of the year (Sunday as the first day of the
  120. week) as a decimal number [00,53].  All days in a new
  121. year preceding the first Sunday are considered to be in
  122. week 0. *
  123. %w  &      Weekday as a decimal number [0(Sunday),6]. *
  124. %W  &      Week number of the year (Monday as the first day of the
  125. week) as a decimal number [00,53].  All days in a new
  126. year preceding the first Sunday are considered to be in
  127. week 0. *
  128. %x  &      Locale's appropriate date representation. *
  129. %X  &      Locale's appropriate time representation. *
  130. %y  &      Year without century as a decimal number [00,99]. *
  131. %Y  &      Year with century as a decimal number. *
  132. %Z  &      Time zone name (or by no characters if no time zone
  133. exists). *
  134. %%  &     % *
  135. <P>
  136. An optional field width and precision specification can immediately
  137. follow the initial % of a directive in the following order: *
  138. <P>
  139. lp25em
  140. [-|0]w  &       the decimal digit string w specifies a minimum field
  141. width in which the result of the conversion is right-
  142. or left-justified.  It is right-justified (with space
  143. padding) by default.  If the optional flag `-' is
  144. specified, it is left-justified with space padding on
  145. the right.  If the optional flag `0' is specified, it
  146. is right-justified and padded with zeros on the left. *
  147. .p      &       the decimal digit string p specifies the minimum number
  148. of digits to appear for the d, H, I, j, m, M, o, S, U,
  149. w, W, y and Y directives, and the maximum number of
  150. characters to be used from the a, A, b, B, c, D, E, F,
  151. h, n, N, p, r, t, T, x, X, z, Z, and 
  152. the first case, if a directive supplies fewer digits
  153. than specified by the precision, it will be expanded
  154. with leading zeros.  In the second case, if a directive
  155. supplies more characters than specified by the
  156. precision, excess characters will truncated on the
  157. right.
  158. <P>
  159. If no field width or precision is specified for a d, H, I, m, M, S, U,
  160. W, y, or j directive, a default of .2 is used for all but j for which
  161. .3 is used.
  162. <P>
  163. </DL>
  164. <DL><DT><B>time</B> () -- function of module time<DD>
  165. Return the time as a floating point number expressed in seconds since
  166. the epoch, in UTC.  Note that even though the time is always returned
  167. as a floating point number, not all systems provide time with a better
  168. precision than 1 second.
  169. </DL>
  170. <DL><DT><B>timezone</B> -- data of module time<DD>
  171. The offset of the local (non-DST) timezone, in seconds west of the 0th
  172. meridian (i.e. negative in most of Western Europe, positive in the US,
  173. zero in the UK).
  174. </DL>
  175. <DL><DT><B>tzname</B> -- data of module time<DD>
  176. A tuple of two strings: the first is the name of the local non-DST
  177. timezone, the second is the name of the local DST timezone.  If no DST
  178. timezone is defined, the second string should not be used.
  179. </DL>
  180.