1
0

ctime 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. .TH CTIME 2
  2. .SH NAME
  3. ctime, localtime, gmtime, asctime, tm2sec, timezone \- convert date and time
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .ta \w'\fLchar* 'u
  10. .B
  11. char* ctime(long clock)
  12. .PP
  13. .B
  14. Tm* localtime(long clock)
  15. .PP
  16. .B
  17. Tm* gmtime(long clock)
  18. .PP
  19. .B
  20. char* asctime(Tm *tm)
  21. .PP
  22. .B
  23. long tm2sec(Tm *tm)
  24. .PP
  25. .B
  26. /env/timezone
  27. .SH DESCRIPTION
  28. .I Ctime
  29. converts a time
  30. .I clock
  31. such as returned by
  32. .IR time (2)
  33. into
  34. .SM ASCII
  35. (sic)
  36. and returns a pointer to a
  37. 30-byte string
  38. in the following form.
  39. All the fields have constant width.
  40. .PP
  41. .B
  42. Wed Aug 5 01:07:47 EST 1973\en\e0
  43. .PP
  44. .I Localtime
  45. and
  46. .I gmtime
  47. return pointers to structures containing
  48. the broken-down time.
  49. .I Localtime
  50. corrects for the time zone and possible daylight savings time;
  51. .I gmtime
  52. converts directly to GMT.
  53. .I Asctime
  54. converts a broken-down time to
  55. .SM ASCII
  56. and returns a pointer
  57. to a 30-byte string.
  58. .IP
  59. .EX
  60. .ta 6n +\w'char 'u +\w'zone[4]; 'u
  61. typedef
  62. struct {
  63. int sec; /* seconds (range 0..59) */
  64. int min; /* minutes (0..59) */
  65. int hour; /* hours (0..23) */
  66. int mday; /* day of the month (1..31) */
  67. int mon; /* month of the year (0..11) */
  68. int year; /* year A.D. \- 1900 */
  69. int wday; /* day of week (0..6, Sunday = 0) */
  70. int yday; /* day of year (0..365) */
  71. char zone[4]; /* time zone name */
  72. int tzoff; /* time zone delta from GMT */
  73. } Tm;
  74. .EE
  75. .PP
  76. .I Tm2sec
  77. converts a broken-down time to
  78. seconds since the start of the epoch.
  79. It ignores
  80. .BR wday ,
  81. and assumes the local time zone
  82. if
  83. .B zone
  84. is not
  85. .BR GMT .
  86. .PP
  87. When local time is first requested,
  88. the program consults the
  89. .B timezone
  90. environment variable to determine the time zone and
  91. converts accordingly.
  92. (This variable is set at system boot time by
  93. .IR init (8).)
  94. The
  95. .B timezone
  96. variable contains
  97. the normal time zone name and its difference from GMT
  98. in seconds followed by an alternate (daylight) time zone name and
  99. its difference followed by a newline.
  100. The remainder is a list of pairs of times
  101. (seconds past the start of 1970, in the first time zone)
  102. when the alternate time zone applies.
  103. For example:
  104. .IP
  105. .EX
  106. EST -18000 EDT -14400
  107. 9943200 25664400 41392800 57718800 ...
  108. .EE
  109. .PP
  110. Greenwich Mean Time is represented by
  111. .IP
  112. .EX
  113. GMT 0
  114. .EE
  115. .SH SOURCE
  116. .B /sys/src/libc/9sys
  117. .SH "SEE ALSO"
  118. .IR date (1),
  119. .IR time (2),
  120. .IR init (8)
  121. .SH BUGS
  122. The return values point to static data
  123. whose content is overwritten by each call.
  124. .br
  125. Daylight Savings Time is ``normal'' in the Southern hemisphere.
  126. .br
  127. These routines are not equipped to handle non-\c
  128. .SM ASCII
  129. text, and are provincial anyway.