You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2170 lines
72 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>time - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package time</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "time"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. <dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd>
  58. </dl>
  59. </div>
  60. <!-- The package's Name is printed as title by the top-level template -->
  61. <div id="pkg-overview" class="toggleVisible">
  62. <div class="collapsed">
  63. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  64. </div>
  65. <div class="expanded">
  66. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  67. <p>
  68. Package time provides functionality for measuring and displaying time.
  69. </p>
  70. <p>
  71. The calendrical calculations always assume a Gregorian calendar.
  72. </p>
  73. </div>
  74. </div>
  75. <div id="pkg-index" class="toggleVisible">
  76. <div class="collapsed">
  77. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  78. </div>
  79. <div class="expanded">
  80. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  81. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  82. <div id="manual-nav">
  83. <dl>
  84. <dd><a href="index.html#pkg-constants">Constants</a></dd>
  85. <dd><a href="index.html#After">func After(d Duration) &lt;-chan Time</a></dd>
  86. <dd><a href="index.html#Sleep">func Sleep(d Duration)</a></dd>
  87. <dd><a href="index.html#Tick">func Tick(d Duration) &lt;-chan Time</a></dd>
  88. <dd><a href="index.html#Duration">type Duration</a></dd>
  89. <dd>&nbsp; &nbsp; <a href="index.html#ParseDuration">func ParseDuration(s string) (Duration, error)</a></dd>
  90. <dd>&nbsp; &nbsp; <a href="index.html#Since">func Since(t Time) Duration</a></dd>
  91. <dd>&nbsp; &nbsp; <a href="index.html#Duration.Hours">func (d Duration) Hours() float64</a></dd>
  92. <dd>&nbsp; &nbsp; <a href="index.html#Duration.Minutes">func (d Duration) Minutes() float64</a></dd>
  93. <dd>&nbsp; &nbsp; <a href="index.html#Duration.Nanoseconds">func (d Duration) Nanoseconds() int64</a></dd>
  94. <dd>&nbsp; &nbsp; <a href="index.html#Duration.Seconds">func (d Duration) Seconds() float64</a></dd>
  95. <dd>&nbsp; &nbsp; <a href="index.html#Duration.String">func (d Duration) String() string</a></dd>
  96. <dd><a href="index.html#Location">type Location</a></dd>
  97. <dd>&nbsp; &nbsp; <a href="index.html#FixedZone">func FixedZone(name string, offset int) *Location</a></dd>
  98. <dd>&nbsp; &nbsp; <a href="index.html#LoadLocation">func LoadLocation(name string) (*Location, error)</a></dd>
  99. <dd>&nbsp; &nbsp; <a href="index.html#Location.String">func (l *Location) String() string</a></dd>
  100. <dd><a href="index.html#Month">type Month</a></dd>
  101. <dd>&nbsp; &nbsp; <a href="index.html#Month.String">func (m Month) String() string</a></dd>
  102. <dd><a href="index.html#ParseError">type ParseError</a></dd>
  103. <dd>&nbsp; &nbsp; <a href="index.html#ParseError.Error">func (e *ParseError) Error() string</a></dd>
  104. <dd><a href="index.html#Ticker">type Ticker</a></dd>
  105. <dd>&nbsp; &nbsp; <a href="index.html#NewTicker">func NewTicker(d Duration) *Ticker</a></dd>
  106. <dd>&nbsp; &nbsp; <a href="index.html#Ticker.Stop">func (t *Ticker) Stop()</a></dd>
  107. <dd><a href="index.html#Time">type Time</a></dd>
  108. <dd>&nbsp; &nbsp; <a href="index.html#Date">func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time</a></dd>
  109. <dd>&nbsp; &nbsp; <a href="index.html#Now">func Now() Time</a></dd>
  110. <dd>&nbsp; &nbsp; <a href="index.html#Parse">func Parse(layout, value string) (Time, error)</a></dd>
  111. <dd>&nbsp; &nbsp; <a href="index.html#ParseInLocation">func ParseInLocation(layout, value string, loc *Location) (Time, error)</a></dd>
  112. <dd>&nbsp; &nbsp; <a href="index.html#Unix">func Unix(sec int64, nsec int64) Time</a></dd>
  113. <dd>&nbsp; &nbsp; <a href="index.html#Time.Add">func (t Time) Add(d Duration) Time</a></dd>
  114. <dd>&nbsp; &nbsp; <a href="index.html#Time.AddDate">func (t Time) AddDate(years int, months int, days int) Time</a></dd>
  115. <dd>&nbsp; &nbsp; <a href="index.html#Time.After">func (t Time) After(u Time) bool</a></dd>
  116. <dd>&nbsp; &nbsp; <a href="index.html#Time.AppendFormat">func (t Time) AppendFormat(b []byte, layout string) []byte</a></dd>
  117. <dd>&nbsp; &nbsp; <a href="index.html#Time.Before">func (t Time) Before(u Time) bool</a></dd>
  118. <dd>&nbsp; &nbsp; <a href="index.html#Time.Clock">func (t Time) Clock() (hour, min, sec int)</a></dd>
  119. <dd>&nbsp; &nbsp; <a href="index.html#Time.Date">func (t Time) Date() (year int, month Month, day int)</a></dd>
  120. <dd>&nbsp; &nbsp; <a href="index.html#Time.Day">func (t Time) Day() int</a></dd>
  121. <dd>&nbsp; &nbsp; <a href="index.html#Time.Equal">func (t Time) Equal(u Time) bool</a></dd>
  122. <dd>&nbsp; &nbsp; <a href="index.html#Time.Format">func (t Time) Format(layout string) string</a></dd>
  123. <dd>&nbsp; &nbsp; <a href="index.html#Time.GobDecode">func (t *Time) GobDecode(data []byte) error</a></dd>
  124. <dd>&nbsp; &nbsp; <a href="index.html#Time.GobEncode">func (t Time) GobEncode() ([]byte, error)</a></dd>
  125. <dd>&nbsp; &nbsp; <a href="index.html#Time.Hour">func (t Time) Hour() int</a></dd>
  126. <dd>&nbsp; &nbsp; <a href="index.html#Time.ISOWeek">func (t Time) ISOWeek() (year, week int)</a></dd>
  127. <dd>&nbsp; &nbsp; <a href="index.html#Time.In">func (t Time) In(loc *Location) Time</a></dd>
  128. <dd>&nbsp; &nbsp; <a href="index.html#Time.IsZero">func (t Time) IsZero() bool</a></dd>
  129. <dd>&nbsp; &nbsp; <a href="index.html#Time.Local">func (t Time) Local() Time</a></dd>
  130. <dd>&nbsp; &nbsp; <a href="index.html#Time.Location">func (t Time) Location() *Location</a></dd>
  131. <dd>&nbsp; &nbsp; <a href="index.html#Time.MarshalBinary">func (t Time) MarshalBinary() ([]byte, error)</a></dd>
  132. <dd>&nbsp; &nbsp; <a href="index.html#Time.MarshalJSON">func (t Time) MarshalJSON() ([]byte, error)</a></dd>
  133. <dd>&nbsp; &nbsp; <a href="index.html#Time.MarshalText">func (t Time) MarshalText() ([]byte, error)</a></dd>
  134. <dd>&nbsp; &nbsp; <a href="index.html#Time.Minute">func (t Time) Minute() int</a></dd>
  135. <dd>&nbsp; &nbsp; <a href="index.html#Time.Month">func (t Time) Month() Month</a></dd>
  136. <dd>&nbsp; &nbsp; <a href="index.html#Time.Nanosecond">func (t Time) Nanosecond() int</a></dd>
  137. <dd>&nbsp; &nbsp; <a href="index.html#Time.Round">func (t Time) Round(d Duration) Time</a></dd>
  138. <dd>&nbsp; &nbsp; <a href="index.html#Time.Second">func (t Time) Second() int</a></dd>
  139. <dd>&nbsp; &nbsp; <a href="index.html#Time.String">func (t Time) String() string</a></dd>
  140. <dd>&nbsp; &nbsp; <a href="index.html#Time.Sub">func (t Time) Sub(u Time) Duration</a></dd>
  141. <dd>&nbsp; &nbsp; <a href="index.html#Time.Truncate">func (t Time) Truncate(d Duration) Time</a></dd>
  142. <dd>&nbsp; &nbsp; <a href="index.html#Time.UTC">func (t Time) UTC() Time</a></dd>
  143. <dd>&nbsp; &nbsp; <a href="index.html#Time.Unix">func (t Time) Unix() int64</a></dd>
  144. <dd>&nbsp; &nbsp; <a href="index.html#Time.UnixNano">func (t Time) UnixNano() int64</a></dd>
  145. <dd>&nbsp; &nbsp; <a href="index.html#Time.UnmarshalBinary">func (t *Time) UnmarshalBinary(data []byte) error</a></dd>
  146. <dd>&nbsp; &nbsp; <a href="index.html#Time.UnmarshalJSON">func (t *Time) UnmarshalJSON(data []byte) (err error)</a></dd>
  147. <dd>&nbsp; &nbsp; <a href="index.html#Time.UnmarshalText">func (t *Time) UnmarshalText(data []byte) (err error)</a></dd>
  148. <dd>&nbsp; &nbsp; <a href="index.html#Time.Weekday">func (t Time) Weekday() Weekday</a></dd>
  149. <dd>&nbsp; &nbsp; <a href="index.html#Time.Year">func (t Time) Year() int</a></dd>
  150. <dd>&nbsp; &nbsp; <a href="index.html#Time.YearDay">func (t Time) YearDay() int</a></dd>
  151. <dd>&nbsp; &nbsp; <a href="index.html#Time.Zone">func (t Time) Zone() (name string, offset int)</a></dd>
  152. <dd><a href="index.html#Timer">type Timer</a></dd>
  153. <dd>&nbsp; &nbsp; <a href="index.html#AfterFunc">func AfterFunc(d Duration, f func()) *Timer</a></dd>
  154. <dd>&nbsp; &nbsp; <a href="index.html#NewTimer">func NewTimer(d Duration) *Timer</a></dd>
  155. <dd>&nbsp; &nbsp; <a href="index.html#Timer.Reset">func (t *Timer) Reset(d Duration) bool</a></dd>
  156. <dd>&nbsp; &nbsp; <a href="index.html#Timer.Stop">func (t *Timer) Stop() bool</a></dd>
  157. <dd><a href="index.html#Weekday">type Weekday</a></dd>
  158. <dd>&nbsp; &nbsp; <a href="index.html#Weekday.String">func (d Weekday) String() string</a></dd>
  159. </dl>
  160. </div><!-- #manual-nav -->
  161. <div id="pkg-examples">
  162. <h4>Examples</h4>
  163. <dl>
  164. <dd><a class="exampleLink" href="index.html#example_After">After</a></dd>
  165. <dd><a class="exampleLink" href="index.html#example_Date">Date</a></dd>
  166. <dd><a class="exampleLink" href="index.html#example_Duration">Duration</a></dd>
  167. <dd><a class="exampleLink" href="index.html#example_Month">Month</a></dd>
  168. <dd><a class="exampleLink" href="index.html#example_Parse">Parse</a></dd>
  169. <dd><a class="exampleLink" href="index.html#example_ParseInLocation">ParseInLocation</a></dd>
  170. <dd><a class="exampleLink" href="index.html#example_Sleep">Sleep</a></dd>
  171. <dd><a class="exampleLink" href="index.html#example_Tick">Tick</a></dd>
  172. <dd><a class="exampleLink" href="index.html#example_Time_Format">Time.Format</a></dd>
  173. <dd><a class="exampleLink" href="index.html#example_Time_Round">Time.Round</a></dd>
  174. <dd><a class="exampleLink" href="index.html#example_Time_Truncate">Time.Truncate</a></dd>
  175. </dl>
  176. </div>
  177. <h4>Package files</h4>
  178. <p>
  179. <span style="font-size:90%">
  180. <a href="http://localhost:6060/src/time/format.go">format.go</a>
  181. <a href="http://localhost:6060/src/time/sleep.go">sleep.go</a>
  182. <a href="http://localhost:6060/src/time/sys_unix.go">sys_unix.go</a>
  183. <a href="http://localhost:6060/src/time/tick.go">tick.go</a>
  184. <a href="http://localhost:6060/src/time/time.go">time.go</a>
  185. <a href="http://localhost:6060/src/time/zoneinfo.go">zoneinfo.go</a>
  186. <a href="http://localhost:6060/src/time/zoneinfo_read.go">zoneinfo_read.go</a>
  187. <a href="http://localhost:6060/src/time/zoneinfo_unix.go">zoneinfo_unix.go</a>
  188. </span>
  189. </p>
  190. </div><!-- .expanded -->
  191. </div><!-- #pkg-index -->
  192. <div id="pkg-callgraph" class="toggle" style="display: none">
  193. <div class="collapsed">
  194. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  195. </div> <!-- .expanded -->
  196. <div class="expanded">
  197. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  198. <p>
  199. In the call graph viewer below, each node
  200. is a function belonging to this package
  201. and its children are the functions it
  202. calls&mdash;perhaps dynamically.
  203. </p>
  204. <p>
  205. The root nodes are the entry points of the
  206. package: functions that may be called from
  207. outside the package.
  208. There may be non-exported or anonymous
  209. functions among them if they are called
  210. dynamically from another package.
  211. </p>
  212. <p>
  213. Click a node to visit that function's source code.
  214. From there you can visit its callers by
  215. clicking its declaring <code>func</code>
  216. token.
  217. </p>
  218. <p>
  219. Functions may be omitted if they were
  220. determined to be unreachable in the
  221. particular programs or tests that were
  222. analyzed.
  223. </p>
  224. <!-- Zero means show all package entry points. -->
  225. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  226. </div>
  227. </div> <!-- #pkg-callgraph -->
  228. <h2 id="pkg-constants">Constants</h2>
  229. <pre>const (
  230. <span id="ANSIC">ANSIC</span> = &#34;Mon Jan _2 15:04:05 2006&#34;
  231. <span id="UnixDate">UnixDate</span> = &#34;Mon Jan _2 15:04:05 MST 2006&#34;
  232. <span id="RubyDate">RubyDate</span> = &#34;Mon Jan 02 15:04:05 -0700 2006&#34;
  233. <span id="RFC822">RFC822</span> = &#34;02 Jan 06 15:04 MST&#34;
  234. <span id="RFC822Z">RFC822Z</span> = &#34;02 Jan 06 15:04 -0700&#34; <span class="comment">// RFC822 with numeric zone</span>
  235. <span id="RFC850">RFC850</span> = &#34;Monday, 02-Jan-06 15:04:05 MST&#34;
  236. <span id="RFC1123">RFC1123</span> = &#34;Mon, 02 Jan 2006 15:04:05 MST&#34;
  237. <span id="RFC1123Z">RFC1123Z</span> = &#34;Mon, 02 Jan 2006 15:04:05 -0700&#34; <span class="comment">// RFC1123 with numeric zone</span>
  238. <span id="RFC3339">RFC3339</span> = &#34;2006-01-02T15:04:05Z07:00&#34;
  239. <span id="RFC3339Nano">RFC3339Nano</span> = &#34;2006-01-02T15:04:05.999999999Z07:00&#34;
  240. <span id="Kitchen">Kitchen</span> = &#34;3:04PM&#34;
  241. <span class="comment">// Handy time stamps.</span>
  242. <span id="Stamp">Stamp</span> = &#34;Jan _2 15:04:05&#34;
  243. <span id="StampMilli">StampMilli</span> = &#34;Jan _2 15:04:05.000&#34;
  244. <span id="StampMicro">StampMicro</span> = &#34;Jan _2 15:04:05.000000&#34;
  245. <span id="StampNano">StampNano</span> = &#34;Jan _2 15:04:05.000000000&#34;
  246. )</pre>
  247. <p>
  248. These are predefined layouts for use in Time.Format and Time.Parse.
  249. The reference time used in the layouts is the specific time:
  250. </p>
  251. <pre>Mon Jan 2 15:04:05 MST 2006
  252. </pre>
  253. <p>
  254. which is Unix time 1136239445. Since MST is GMT-0700,
  255. the reference time can be thought of as
  256. </p>
  257. <pre>01/02 03:04:05PM &#39;06 -0700
  258. </pre>
  259. <p>
  260. To define your own format, write down what the reference time would look
  261. like formatted your way; see the values of constants like ANSIC,
  262. StampMicro or Kitchen for examples. The model is to demonstrate what the
  263. reference time looks like so that the Format and Parse methods can apply
  264. the same transformation to a general time value.
  265. </p>
  266. <p>
  267. Within the format string, an underscore _ represents a space that may be
  268. replaced by a digit if the following number (a day) has two digits; for
  269. compatibility with fixed-width Unix time formats.
  270. </p>
  271. <p>
  272. A decimal point followed by one or more zeros represents a fractional
  273. second, printed to the given number of decimal places. A decimal point
  274. followed by one or more nines represents a fractional second, printed to
  275. the given number of decimal places, with trailing zeros removed.
  276. When parsing (only), the input may contain a fractional second
  277. field immediately after the seconds field, even if the layout does not
  278. signify its presence. In that case a decimal point followed by a maximal
  279. series of digits is parsed as a fractional second.
  280. </p>
  281. <p>
  282. Numeric time zone offsets format as follows:
  283. </p>
  284. <pre>-0700 ±hhmm
  285. -07:00 ±hh:mm
  286. -07 ±hh
  287. </pre>
  288. <p>
  289. Replacing the sign in the format with a Z triggers
  290. the ISO 8601 behavior of printing Z instead of an
  291. offset for the UTC zone. Thus:
  292. </p>
  293. <pre>Z0700 Z or ±hhmm
  294. Z07:00 Z or ±hh:mm
  295. Z07 Z or ±hh
  296. </pre>
  297. <p>
  298. The executable example for time.Format demonstrates the working
  299. of the layout string in detail and is a good reference.
  300. </p>
  301. <p>
  302. Note that the RFC822, RFC850, and RFC1123 formats should be applied
  303. only to local times. Applying them to UTC times will use &#34;UTC&#34; as the
  304. time zone abbreviation, while strictly speaking those RFCs require the
  305. use of &#34;GMT&#34; in that case.
  306. In general RFC1123Z should be used instead of RFC1123 for servers
  307. that insist on that format, and RFC3339 should be preferred for new protocols.
  308. </p>
  309. <h2 id="After">func <a href="http://localhost:6060/src/time/sleep.go?s=3012:3046#L99">After</a></h2>
  310. <pre>func After(d <a href="index.html#Duration">Duration</a>) &lt;-chan <a href="index.html#Time">Time</a></pre>
  311. <p>
  312. After waits for the duration to elapse and then sends the current time
  313. on the returned channel.
  314. It is equivalent to NewTimer(d).C.
  315. </p>
  316. <div id="example_After" class="toggle">
  317. <div class="collapsed">
  318. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  319. </div>
  320. <div class="expanded">
  321. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  322. <p>Code:</p>
  323. <pre class="code">
  324. select {
  325. case m := &lt;-c:
  326. handle(m)
  327. case &lt;-time.After(5 * time.Minute):
  328. fmt.Println(&#34;timed out&#34;)
  329. }
  330. </pre>
  331. </div>
  332. </div>
  333. <h2 id="Sleep">func <a href="http://localhost:6060/src/time/sleep.go?s=308:330#L1">Sleep</a></h2>
  334. <pre>func Sleep(d <a href="index.html#Duration">Duration</a>)</pre>
  335. <p>
  336. Sleep pauses the current goroutine for at least the duration d.
  337. A negative or zero duration causes Sleep to return immediately.
  338. </p>
  339. <div id="example_Sleep" class="toggle">
  340. <div class="collapsed">
  341. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  342. </div>
  343. <div class="expanded">
  344. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  345. <p>Code:</p>
  346. <pre class="code">
  347. time.Sleep(100 * time.Millisecond)
  348. </pre>
  349. </div>
  350. </div>
  351. <h2 id="Tick">func <a href="http://localhost:6060/src/time/tick.go?s=1667:1700#L43">Tick</a></h2>
  352. <pre>func Tick(d <a href="index.html#Duration">Duration</a>) &lt;-chan <a href="index.html#Time">Time</a></pre>
  353. <p>
  354. Tick is a convenience wrapper for NewTicker providing access to the ticking
  355. channel only. While Tick is useful for clients that have no need to shut down
  356. the Ticker, be aware that without a way to shut it down the underlying
  357. Ticker cannot be recovered by the garbage collector; it &#34;leaks&#34;.
  358. </p>
  359. <div id="example_Tick" class="toggle">
  360. <div class="collapsed">
  361. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  362. </div>
  363. <div class="expanded">
  364. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  365. <p>Code:</p>
  366. <pre class="code">
  367. c := time.Tick(1 * time.Minute)
  368. for now := range c {
  369. fmt.Printf(&#34;%v %s\n&#34;, now, statusUpdate())
  370. }
  371. </pre>
  372. </div>
  373. </div>
  374. <h2 id="Duration">type <a href="http://localhost:6060/src/time/time.go?s=13980:13999#L420">Duration</a></h2>
  375. <pre>type Duration <a href="../builtin/index.html#int64">int64</a></pre>
  376. <p>
  377. A Duration represents the elapsed time between two instants
  378. as an int64 nanosecond count. The representation limits the
  379. largest representable duration to approximately 290 years.
  380. </p>
  381. <pre>const (
  382. <span id="Nanosecond">Nanosecond</span> <a href="index.html#Duration">Duration</a> = 1
  383. <span id="Microsecond">Microsecond</span> = 1000 * <a href="index.html#Nanosecond">Nanosecond</a>
  384. <span id="Millisecond">Millisecond</span> = 1000 * <a href="index.html#Microsecond">Microsecond</a>
  385. <span id="Second">Second</span> = 1000 * <a href="index.html#Millisecond">Millisecond</a>
  386. <span id="Minute">Minute</span> = 60 * <a href="index.html#Second">Second</a>
  387. <span id="Hour">Hour</span> = 60 * <a href="index.html#Minute">Minute</a>
  388. )</pre>
  389. <p>
  390. Common durations. There is no definition for units of Day or larger
  391. to avoid confusion across daylight savings time zone transitions.
  392. </p>
  393. <p>
  394. To count the number of units in a Duration, divide:
  395. </p>
  396. <pre>second := time.Second
  397. fmt.Print(int64(second/time.Millisecond)) // prints 1000
  398. </pre>
  399. <p>
  400. To convert an integer number of units to a Duration, multiply:
  401. </p>
  402. <pre>seconds := 10
  403. fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
  404. </pre>
  405. <div id="example_Duration" class="toggle">
  406. <div class="collapsed">
  407. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  408. </div>
  409. <div class="expanded">
  410. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  411. <p>Code:</p>
  412. <pre class="code">
  413. t0 := time.Now()
  414. expensiveCall()
  415. t1 := time.Now()
  416. fmt.Printf(&#34;The call took %v to run.\n&#34;, t1.Sub(t0))
  417. </pre>
  418. </div>
  419. </div>
  420. <h3 id="ParseDuration">func <a href="http://localhost:6060/src/time/format.go?s=35149:35195#L1179">ParseDuration</a></h3>
  421. <pre>func ParseDuration(s <a href="../builtin/index.html#string">string</a>) (<a href="index.html#Duration">Duration</a>, <a href="../builtin/index.html#error">error</a>)</pre>
  422. <p>
  423. ParseDuration parses a duration string.
  424. A duration string is a possibly signed sequence of
  425. decimal numbers, each with optional fraction and a unit suffix,
  426. such as &#34;300ms&#34;, &#34;-1.5h&#34; or &#34;2h45m&#34;.
  427. Valid time units are &#34;ns&#34;, &#34;us&#34; (or &#34;µs&#34;), &#34;ms&#34;, &#34;s&#34;, &#34;m&#34;, &#34;h&#34;.
  428. </p>
  429. <h3 id="Since">func <a href="http://localhost:6060/src/time/time.go?s=19263:19290#L633">Since</a></h3>
  430. <pre>func Since(t <a href="index.html#Time">Time</a>) <a href="index.html#Duration">Duration</a></pre>
  431. <p>
  432. Since returns the time elapsed since t.
  433. It is shorthand for time.Now().Sub(t).
  434. </p>
  435. <h3 id="Duration.Hours">func (Duration) <a href="http://localhost:6060/src/time/time.go?s=18219:18252#L593">Hours</a></h3>
  436. <pre>func (d <a href="index.html#Duration">Duration</a>) Hours() <a href="../builtin/index.html#float64">float64</a></pre>
  437. <p>
  438. Hours returns the duration as a floating point number of hours.
  439. </p>
  440. <h3 id="Duration.Minutes">func (Duration) <a href="http://localhost:6060/src/time/time.go?s=18025:18060#L586">Minutes</a></h3>
  441. <pre>func (d <a href="index.html#Duration">Duration</a>) Minutes() <a href="../builtin/index.html#float64">float64</a></pre>
  442. <p>
  443. Minutes returns the duration as a floating point number of minutes.
  444. </p>
  445. <h3 id="Duration.Nanoseconds">func (Duration) <a href="http://localhost:6060/src/time/time.go?s=17239:17276#L567">Nanoseconds</a></h3>
  446. <pre>func (d <a href="index.html#Duration">Duration</a>) Nanoseconds() <a href="../builtin/index.html#int64">int64</a></pre>
  447. <p>
  448. Nanoseconds returns the duration as an integer nanosecond count.
  449. </p>
  450. <h3 id="Duration.Seconds">func (Duration) <a href="http://localhost:6060/src/time/time.go?s=17832:17867#L579">Seconds</a></h3>
  451. <pre>func (d <a href="index.html#Duration">Duration</a>) Seconds() <a href="../builtin/index.html#float64">float64</a></pre>
  452. <p>
  453. Seconds returns the duration as a floating point number of seconds.
  454. </p>
  455. <h3 id="Duration.String">func (Duration) <a href="http://localhost:6060/src/time/time.go?s=15077:15110#L452">String</a></h3>
  456. <pre>func (d <a href="index.html#Duration">Duration</a>) String() <a href="../builtin/index.html#string">string</a></pre>
  457. <p>
  458. String returns a string representing the duration in the form &#34;72h3m0.5s&#34;.
  459. Leading zero units are omitted. As a special case, durations less than one
  460. second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure
  461. that the leading digit is non-zero. The zero duration formats as 0,
  462. with no unit.
  463. </p>
  464. <h2 id="Location">type <a href="http://localhost:6060/src/time/zoneinfo.go?s=415:930#L5">Location</a></h2>
  465. <pre>type Location struct {
  466. <span class="comment">// contains filtered or unexported fields</span>
  467. }</pre>
  468. <p>
  469. A Location maps time instants to the zone in use at that time.
  470. Typically, the Location represents the collection of time offsets
  471. in use in a geographical area, such as CEST and CET for central Europe.
  472. </p>
  473. <pre>var <span id="Local">Local</span> *<a href="index.html#Location">Location</a> = &amp;localLoc</pre>
  474. <p>
  475. Local represents the system&#39;s local time zone.
  476. </p>
  477. <pre>var <span id="UTC">UTC</span> *<a href="index.html#Location">Location</a> = &amp;utcLoc</pre>
  478. <p>
  479. UTC represents Universal Coordinated Time (UTC).
  480. </p>
  481. <h3 id="FixedZone">func <a href="http://localhost:6060/src/time/zoneinfo.go?s=2522:2571#L79">FixedZone</a></h3>
  482. <pre>func FixedZone(name <a href="../builtin/index.html#string">string</a>, offset <a href="../builtin/index.html#int">int</a>) *<a href="index.html#Location">Location</a></pre>
  483. <p>
  484. FixedZone returns a Location that always uses
  485. the given zone name and offset (seconds east of UTC).
  486. </p>
  487. <h3 id="LoadLocation">func <a href="http://localhost:6060/src/time/zoneinfo.go?s=7498:7547#L263">LoadLocation</a></h3>
  488. <pre>func LoadLocation(name <a href="../builtin/index.html#string">string</a>) (*<a href="index.html#Location">Location</a>, <a href="../builtin/index.html#error">error</a>)</pre>
  489. <p>
  490. LoadLocation returns the Location with the given name.
  491. </p>
  492. <p>
  493. If the name is &#34;&#34; or &#34;UTC&#34;, LoadLocation returns UTC.
  494. If the name is &#34;Local&#34;, LoadLocation returns Local.
  495. </p>
  496. <p>
  497. Otherwise, the name is taken to be a location name corresponding to a file
  498. in the IANA Time Zone database, such as &#34;America/New_York&#34;.
  499. </p>
  500. <p>
  501. The time zone database needed by LoadLocation may not be
  502. present on all systems, especially non-Unix systems.
  503. LoadLocation looks in the directory or uncompressed zip file
  504. named by the ZONEINFO environment variable, if any, then looks in
  505. known installation locations on Unix systems,
  506. and finally looks in $GOROOT/lib/time/zoneinfo.zip.
  507. </p>
  508. <h3 id="Location.String">func (*Location) <a href="http://localhost:6060/src/time/zoneinfo.go?s=2355:2389#L73">String</a></h3>
  509. <pre>func (l *<a href="index.html#Location">Location</a>) String() <a href="../builtin/index.html#string">string</a></pre>
  510. <p>
  511. String returns a descriptive name for the time zone information,
  512. corresponding to the argument to LoadLocation.
  513. </p>
  514. <h2 id="Month">type <a href="http://localhost:6060/src/time/time.go?s=3100:3114#L67">Month</a></h2>
  515. <pre>type Month <a href="../builtin/index.html#int">int</a></pre>
  516. <p>
  517. A Month specifies a month of the year (January = 1, ...).
  518. </p>
  519. <pre>const (
  520. <span id="January">January</span> <a href="index.html#Month">Month</a> = 1 + <a href="../builtin/index.html#iota">iota</a>
  521. <span id="February">February</span>
  522. <span id="March">March</span>
  523. <span id="April">April</span>
  524. <span id="May">May</span>
  525. <span id="June">June</span>
  526. <span id="July">July</span>
  527. <span id="August">August</span>
  528. <span id="September">September</span>
  529. <span id="October">October</span>
  530. <span id="November">November</span>
  531. <span id="December">December</span>
  532. )</pre>
  533. <div id="example_Month" class="toggle">
  534. <div class="collapsed">
  535. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  536. </div>
  537. <div class="expanded">
  538. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  539. <p>Code:</p>
  540. <pre class="code">
  541. _, month, day := time.Now().Date()
  542. if month == time.November &amp;&amp; day == 10 {
  543. fmt.Println(&#34;Happy Go day!&#34;)
  544. }
  545. </pre>
  546. </div>
  547. </div>
  548. <h3 id="Month.String">func (Month) <a href="http://localhost:6060/src/time/time.go?s=3483:3513#L100">String</a></h3>
  549. <pre>func (m <a href="index.html#Month">Month</a>) String() <a href="../builtin/index.html#string">string</a></pre>
  550. <p>
  551. String returns the English name of the month (&#34;January&#34;, &#34;February&#34;, ...).
  552. </p>
  553. <h2 id="ParseError">type <a href="http://localhost:6060/src/time/format.go?s=18238:18359#L601">ParseError</a></h2>
  554. <pre>type ParseError struct {
  555. Layout <a href="../builtin/index.html#string">string</a>
  556. Value <a href="../builtin/index.html#string">string</a>
  557. LayoutElem <a href="../builtin/index.html#string">string</a>
  558. ValueElem <a href="../builtin/index.html#string">string</a>
  559. Message <a href="../builtin/index.html#string">string</a>
  560. }</pre>
  561. <p>
  562. ParseError describes a problem parsing a time string.
  563. </p>
  564. <h3 id="ParseError.Error">func (*ParseError) <a href="http://localhost:6060/src/time/format.go?s=18478:18513#L614">Error</a></h3>
  565. <pre>func (e *<a href="index.html#ParseError">ParseError</a>) Error() <a href="../builtin/index.html#string">string</a></pre>
  566. <p>
  567. Error returns the string representation of a ParseError.
  568. </p>
  569. <h2 id="Ticker">type <a href="http://localhost:6060/src/time/tick.go?s=269:371#L1">Ticker</a></h2>
  570. <pre>type Ticker struct {
  571. C &lt;-chan <a href="index.html#Time">Time</a> <span class="comment">// The channel on which the ticks are delivered.</span>
  572. <span class="comment">// contains filtered or unexported fields</span>
  573. }</pre>
  574. <p>
  575. A Ticker holds a channel that delivers `ticks&#39; of a clock
  576. at intervals.
  577. </p>
  578. <h3 id="NewTicker">func <a href="http://localhost:6060/src/time/tick.go?s=706:740#L11">NewTicker</a></h3>
  579. <pre>func NewTicker(d <a href="index.html#Duration">Duration</a>) *<a href="index.html#Ticker">Ticker</a></pre>
  580. <p>
  581. NewTicker returns a new Ticker containing a channel that will send the
  582. time with a period specified by the duration argument.
  583. It adjusts the intervals or drops ticks to make up for slow receivers.
  584. The duration d must be greater than zero; if not, NewTicker will panic.
  585. Stop the ticker to release associated resources.
  586. </p>
  587. <h3 id="Ticker.Stop">func (*Ticker) <a href="http://localhost:6060/src/time/tick.go?s=1319:1342#L35">Stop</a></h3>
  588. <pre>func (t *<a href="index.html#Ticker">Ticker</a>) Stop()</pre>
  589. <p>
  590. Stop turns off a ticker. After Stop, no more ticks will be sent.
  591. Stop does not close the channel, to prevent a read from the channel succeeding
  592. incorrectly.
  593. </p>
  594. <h2 id="Time">type <a href="http://localhost:6060/src/time/time.go?s=1855:2369#L29">Time</a></h2>
  595. <pre>type Time struct {
  596. <span class="comment">// contains filtered or unexported fields</span>
  597. }</pre>
  598. <p>
  599. A Time represents an instant in time with nanosecond precision.
  600. </p>
  601. <p>
  602. Programs using times should typically store and pass them as values,
  603. not pointers. That is, time variables and struct fields should be of
  604. type time.Time, not *time.Time. A Time value can be used by
  605. multiple goroutines simultaneously.
  606. </p>
  607. <p>
  608. Time instants can be compared using the Before, After, and Equal methods.
  609. The Sub method subtracts two instants, producing a Duration.
  610. The Add method adds a Time and a Duration, producing a Time.
  611. </p>
  612. <p>
  613. The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC.
  614. As this time is unlikely to come up in practice, the IsZero method gives
  615. a simple way of detecting a time that has not been initialized explicitly.
  616. </p>
  617. <p>
  618. Each Time has associated with it a Location, consulted when computing the
  619. presentation form of the time, such as in the Format, Hour, and Year methods.
  620. The methods Local, UTC, and In return a Time with a specific location.
  621. Changing the location in this way changes only the presentation; it does not
  622. change the instant in time being denoted and therefore does not affect the
  623. computations described in earlier paragraphs.
  624. </p>
  625. <p>
  626. Note that the Go == operator compares not just the time instant but also the
  627. Location. Therefore, Time values should not be used as map or database keys
  628. without first guaranteeing that the identical Location has been set for all
  629. values, which can be achieved through use of the UTC or Local method.
  630. </p>
  631. <h3 id="Date">func <a href="http://localhost:6060/src/time/time.go?s=30075:30158#L1018">Date</a></h3>
  632. <pre>func Date(year <a href="../builtin/index.html#int">int</a>, month <a href="index.html#Month">Month</a>, day, hour, min, sec, nsec <a href="../builtin/index.html#int">int</a>, loc *<a href="index.html#Location">Location</a>) <a href="index.html#Time">Time</a></pre>
  633. <p>
  634. Date returns the Time corresponding to
  635. </p>
  636. <pre>yyyy-mm-dd hh:mm:ss + nsec nanoseconds
  637. </pre>
  638. <p>
  639. in the appropriate zone for that time in the given location.
  640. </p>
  641. <p>
  642. The month, day, hour, min, sec, and nsec values may be outside
  643. their usual ranges and will be normalized during the conversion.
  644. For example, October 32 converts to November 1.
  645. </p>
  646. <p>
  647. A daylight savings time transition skips or repeats times.
  648. For example, in the United States, March 13, 2011 2:15am never occurred,
  649. while November 6, 2011 1:15am occurred twice. In such cases, the
  650. choice of time zone, and therefore the time, is not well-defined.
  651. Date returns a time that is correct in one of the two zones involved
  652. in the transition, but it does not guarantee which.
  653. </p>
  654. <p>
  655. Date panics if loc is nil.
  656. </p>
  657. <div id="example_Date" class="toggle">
  658. <div class="collapsed">
  659. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  660. </div>
  661. <div class="expanded">
  662. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  663. <p>Code:</p>
  664. <pre class="code">t := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
  665. fmt.Printf(&#34;Go launched at %s\n&#34;, t.Local())
  666. <span class="comment"></pre>
  667. <p>Output:</p>
  668. <pre class="output">Go launched at 2009-11-10 15:00:00 -0800 PST
  669. </pre>
  670. </div>
  671. </div>
  672. <h3 id="Now">func <a href="http://localhost:6060/src/time/time.go?s=22856:22871#L771">Now</a></h3>
  673. <pre>func Now() <a href="index.html#Time">Time</a></pre>
  674. <p>
  675. Now returns the current local time.
  676. </p>
  677. <h3 id="Parse">func <a href="http://localhost:6060/src/time/format.go?s=22436:22482#L722">Parse</a></h3>
  678. <pre>func Parse(layout, value <a href="../builtin/index.html#string">string</a>) (<a href="index.html#Time">Time</a>, <a href="../builtin/index.html#error">error</a>)</pre>
  679. <p>
  680. Parse parses a formatted string and returns the time value it represents.
  681. The layout defines the format by showing how the reference time,
  682. defined to be
  683. </p>
  684. <pre>Mon Jan 2 15:04:05 -0700 MST 2006
  685. </pre>
  686. <p>
  687. would be interpreted if it were the value; it serves as an example of
  688. the input format. The same interpretation will then be made to the
  689. input string.
  690. </p>
  691. <p>
  692. Predefined layouts ANSIC, UnixDate, RFC3339 and others describe standard
  693. and convenient representations of the reference time. For more information
  694. about the formats and the definition of the reference time, see the
  695. documentation for ANSIC and the other constants defined by this package.
  696. Also, the executable example for time.Format demonstrates the working
  697. of the layout string in detail and is a good reference.
  698. </p>
  699. <p>
  700. Elements omitted from the value are assumed to be zero or, when
  701. zero is impossible, one, so parsing &#34;3:04pm&#34; returns the time
  702. corresponding to Jan 1, year 0, 15:04:00 UTC (note that because the year is
  703. 0, this time is before the zero Time).
  704. Years must be in the range 0000..9999. The day of the week is checked
  705. for syntax but it is otherwise ignored.
  706. </p>
  707. <p>
  708. In the absence of a time zone indicator, Parse returns a time in UTC.
  709. </p>
  710. <p>
  711. When parsing a time with a zone offset like -0700, if the offset corresponds
  712. to a time zone used by the current location (Local), then Parse uses that
  713. location and zone in the returned time. Otherwise it records the time as
  714. being in a fabricated location with time fixed at the given zone offset.
  715. </p>
  716. <p>
  717. No checking is done that the day of the month is within the month&#39;s
  718. valid dates; any one- or two-digit value is accepted. For example
  719. February 31 and even February 99 are valid dates, specifying dates
  720. in March and May. This behavior is consistent with time.Date.
  721. </p>
  722. <p>
  723. When parsing a time with a zone abbreviation like MST, if the zone abbreviation
  724. has a defined offset in the current location, then that offset is used.
  725. The zone abbreviation &#34;UTC&#34; is recognized as UTC regardless of location.
  726. If the zone abbreviation is unknown, Parse records the time as being
  727. in a fabricated location with the given zone abbreviation and a zero offset.
  728. This choice means that such a time can be parsed and reformatted with the
  729. same layout losslessly, but the exact instant used in the representation will
  730. differ by the actual zone offset. To avoid such problems, prefer time layouts
  731. that use a numeric zone offset, or use ParseInLocation.
  732. </p>
  733. <div id="example_Parse" class="toggle">
  734. <div class="collapsed">
  735. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  736. </div>
  737. <div class="expanded">
  738. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  739. <p>Code:</p>
  740. <pre class="code"><span class="comment">// See the example for time.Format for a thorough description of how</span>
  741. <span class="comment">// to define the layout string to parse a time.Time value; Parse and</span>
  742. <span class="comment">// Format use the same model to describe their input and output.</span>
  743. <span class="comment">// longForm shows by example how the reference time would be represented in</span>
  744. <span class="comment">// the desired layout.</span>
  745. const longForm = &#34;Jan 2, 2006 at 3:04pm (MST)&#34;
  746. t, _ := time.Parse(longForm, &#34;Feb 3, 2013 at 7:54pm (PST)&#34;)
  747. fmt.Println(t)
  748. <span class="comment">// shortForm is another way the reference time would be represented</span>
  749. <span class="comment">// in the desired layout; it has no time zone present.</span>
  750. <span class="comment">// Note: without explicit zone, returns time in UTC.</span>
  751. const shortForm = &#34;2006-Jan-02&#34;
  752. t, _ = time.Parse(shortForm, &#34;2013-Feb-03&#34;)
  753. fmt.Println(t)
  754. <span class="comment"></pre>
  755. <p>Output:</p>
  756. <pre class="output">2013-02-03 19:54:00 -0800 PST
  757. 2013-02-03 00:00:00 +0000 UTC
  758. </pre>
  759. </div>
  760. </div>
  761. <h3 id="ParseInLocation">func <a href="http://localhost:6060/src/time/format.go?s=22894:22965#L731">ParseInLocation</a></h3>
  762. <pre>func ParseInLocation(layout, value <a href="../builtin/index.html#string">string</a>, loc *<a href="index.html#Location">Location</a>) (<a href="index.html#Time">Time</a>, <a href="../builtin/index.html#error">error</a>)</pre>
  763. <p>
  764. ParseInLocation is like Parse but differs in two important ways.
  765. First, in the absence of time zone information, Parse interprets a time as UTC;
  766. ParseInLocation interprets the time as in the given location.
  767. Second, when given a zone offset or abbreviation, Parse tries to match it
  768. against the Local location; ParseInLocation uses the given location.
  769. </p>
  770. <div id="example_ParseInLocation" class="toggle">
  771. <div class="collapsed">
  772. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  773. </div>
  774. <div class="expanded">
  775. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  776. <p>Code:</p>
  777. <pre class="code">loc, _ := time.LoadLocation(&#34;Europe/Berlin&#34;)
  778. const longForm = &#34;Jan 2, 2006 at 3:04pm (MST)&#34;
  779. t, _ := time.ParseInLocation(longForm, &#34;Jul 9, 2012 at 5:02am (CEST)&#34;, loc)
  780. fmt.Println(t)
  781. <span class="comment">// Note: without explicit zone, returns time in given location.</span>
  782. const shortForm = &#34;2006-Jan-02&#34;
  783. t, _ = time.ParseInLocation(shortForm, &#34;2012-Jul-09&#34;, loc)
  784. fmt.Println(t)
  785. <span class="comment"></pre>
  786. <p>Output:</p>
  787. <pre class="output">2012-07-09 05:02:00 +0200 CEST
  788. 2012-07-09 00:00:00 +0200 CEST
  789. </pre>
  790. </div>
  791. </div>
  792. <h3 id="Unix">func <a href="http://localhost:6060/src/time/time.go?s=28704:28741#L968">Unix</a></h3>
  793. <pre>func Unix(sec <a href="../builtin/index.html#int64">int64</a>, nsec <a href="../builtin/index.html#int64">int64</a>) <a href="index.html#Time">Time</a></pre>
  794. <p>
  795. Unix returns the local Time corresponding to the given Unix time,
  796. sec seconds and nsec nanoseconds since January 1, 1970 UTC.
  797. It is valid to pass nsec outside the range [0, 999999999].
  798. Not all sec values have a corresponding time value. One such
  799. value is 1&lt;&lt;63-1 (the largest int64 value).
  800. </p>
  801. <h3 id="Time.Add">func (Time) <a href="http://localhost:6060/src/time/time.go?s=18374:18408#L600">Add</a></h3>
  802. <pre>func (t <a href="index.html#Time">Time</a>) Add(d <a href="index.html#Duration">Duration</a>) <a href="index.html#Time">Time</a></pre>
  803. <p>
  804. Add returns the time t+d.
  805. </p>
  806. <h3 id="Time.AddDate">func (Time) <a href="http://localhost:6060/src/time/time.go?s=19687:19746#L645">AddDate</a></h3>
  807. <pre>func (t <a href="index.html#Time">Time</a>) AddDate(years <a href="../builtin/index.html#int">int</a>, months <a href="../builtin/index.html#int">int</a>, days <a href="../builtin/index.html#int">int</a>) <a href="index.html#Time">Time</a></pre>
  808. <p>
  809. AddDate returns the time corresponding to adding the
  810. given number of years, months, and days to t.
  811. For example, AddDate(-1, 2, 3) applied to January 1, 2011
  812. returns March 4, 2010.
  813. </p>
  814. <p>
  815. AddDate normalizes its result in the same way that Date does,
  816. so, for example, adding one month to October 31 yields
  817. December 1, the normalized form for November 31.
  818. </p>
  819. <h3 id="Time.After">func (Time) <a href="http://localhost:6060/src/time/time.go?s=2427:2459#L48">After</a></h3>
  820. <pre>func (t <a href="index.html#Time">Time</a>) After(u <a href="index.html#Time">Time</a>) <a href="../builtin/index.html#bool">bool</a></pre>
  821. <p>
  822. After reports whether the time instant t is after u.
  823. </p>
  824. <h3 id="Time.AppendFormat">func (Time) <a href="http://localhost:6060/src/time/format.go?s=14187:14245#L443">AppendFormat</a></h3>
  825. <pre>func (t <a href="index.html#Time">Time</a>) AppendFormat(b []<a href="../builtin/index.html#byte">byte</a>, layout <a href="../builtin/index.html#string">string</a>) []<a href="../builtin/index.html#byte">byte</a></pre>
  826. <p>
  827. AppendFormat is like Format but appends the textual
  828. representation to b and returns the extended buffer.
  829. </p>
  830. <h3 id="Time.Before">func (Time) <a href="http://localhost:6060/src/time/time.go?s=2582:2615#L53">Before</a></h3>
  831. <pre>func (t <a href="index.html#Time">Time</a>) Before(u <a href="index.html#Time">Time</a>) <a href="../builtin/index.html#bool">bool</a></pre>
  832. <p>
  833. Before reports whether the time instant t is before u.
  834. </p>
  835. <h3 id="Time.Clock">func (Time) <a href="http://localhost:6060/src/time/time.go?s=12570:12612#L375">Clock</a></h3>
  836. <pre>func (t <a href="index.html#Time">Time</a>) Clock() (hour, min, sec <a href="../builtin/index.html#int">int</a>)</pre>
  837. <p>
  838. Clock returns the hour, minute, and second within the day specified by t.
  839. </p>
  840. <h3 id="Time.Date">func (Time) <a href="http://localhost:6060/src/time/time.go?s=9862:9915#L280">Date</a></h3>
  841. <pre>func (t <a href="index.html#Time">Time</a>) Date() (year <a href="../builtin/index.html#int">int</a>, month <a href="index.html#Month">Month</a>, day <a href="../builtin/index.html#int">int</a>)</pre>
  842. <p>
  843. Date returns the year, month, and day in which t occurs.
  844. </p>
  845. <h3 id="Time.Day">func (Time) <a href="http://localhost:6060/src/time/time.go?s=10270:10293#L298">Day</a></h3>
  846. <pre>func (t <a href="index.html#Time">Time</a>) Day() <a href="../builtin/index.html#int">int</a></pre>
  847. <p>
  848. Day returns the day of the month specified by t.
  849. </p>
  850. <h3 id="Time.Equal">func (Time) <a href="http://localhost:6060/src/time/time.go?s=2958:2990#L62">Equal</a></h3>
  851. <pre>func (t <a href="index.html#Time">Time</a>) Equal(u <a href="index.html#Time">Time</a>) <a href="../builtin/index.html#bool">bool</a></pre>
  852. <p>
  853. Equal reports whether t and u represent the same time instant.
  854. Two times can be equal even if they are in different locations.
  855. For example, 6:00 +0200 CEST and 4:00 UTC are Equal.
  856. This comparison is different from using t == u, which also compares
  857. the locations.
  858. </p>
  859. <h3 id="Time.Format">func (Time) <a href="http://localhost:6060/src/time/format.go?s=13822:13864#L427">Format</a></h3>
  860. <pre>func (t <a href="index.html#Time">Time</a>) Format(layout <a href="../builtin/index.html#string">string</a>) <a href="../builtin/index.html#string">string</a></pre>
  861. <p>
  862. Format returns a textual representation of the time value formatted
  863. according to layout, which defines the format by showing how the reference
  864. time, defined to be
  865. </p>
  866. <pre>Mon Jan 2 15:04:05 -0700 MST 2006
  867. </pre>
  868. <p>
  869. would be displayed if it were the value; it serves as an example of the
  870. desired output. The same display rules will then be applied to the time
  871. value.
  872. </p>
  873. <p>
  874. A fractional second is represented by adding a period and zeros
  875. to the end of the seconds section of layout string, as in &#34;15:04:05.000&#34;
  876. to format a time stamp with millisecond precision.
  877. </p>
  878. <p>
  879. Predefined layouts ANSIC, UnixDate, RFC3339 and others describe standard
  880. and convenient representations of the reference time. For more information
  881. about the formats and the definition of the reference time, see the
  882. documentation for ANSIC and the other constants defined by this package.
  883. </p>
  884. <div id="example_Time_Format" class="toggle">
  885. <div class="collapsed">
  886. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  887. </div>
  888. <div class="expanded">
  889. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  890. <p>Code:</p>
  891. <pre class="code"><span class="comment">// Parse a time value from a string in the standard Unix format.</span>
  892. t, err := time.Parse(time.UnixDate, &#34;Sat Mar 7 11:06:39 PST 2015&#34;)
  893. if err != nil { <span class="comment">// Always check errors even if they should not happen.</span>
  894. panic(err)
  895. }
  896. <span class="comment">// time.Time&#39;s Stringer method is useful without any format.</span>
  897. fmt.Println(&#34;default format:&#34;, t)
  898. <span class="comment">// Predefined constants in the package implement common layouts.</span>
  899. fmt.Println(&#34;Unix format:&#34;, t.Format(time.UnixDate))
  900. <span class="comment">// The time zone attached to the time value affects its output.</span>
  901. fmt.Println(&#34;Same, in UTC:&#34;, t.UTC().Format(time.UnixDate))
  902. <span class="comment">// The rest of this function demonstrates the properties of the</span>
  903. <span class="comment">// layout string used in the format.</span>
  904. <span class="comment">// The layout string used by the Parse function and Format method</span>
  905. <span class="comment">// shows by example how the reference time should be represented.</span>
  906. <span class="comment">// We stress that one must show how the reference time is formatted,</span>
  907. <span class="comment">// not a time of the user&#39;s choosing. Thus each layout string is a</span>
  908. <span class="comment">// representation of the time stamp,</span>
  909. <span class="comment">// Jan 2 15:04:05 2006 MST</span>
  910. <span class="comment">// An easy way to remember this value is that it holds, when presented</span>
  911. <span class="comment">// in this order, the values (lined up with the elements above):</span>
  912. <span class="comment">// 1 2 3 4 5 6 -7</span>
  913. <span class="comment">// There are some wrinkles illustrated below.</span>
  914. <span class="comment">// Most uses of Format and Parse use constant layout strings such as</span>
  915. <span class="comment">// the ones defined in this package, but the interface is flexible,</span>
  916. <span class="comment">// as these examples show.</span>
  917. <span class="comment">// Define a helper function to make the examples&#39; output look nice.</span>
  918. do := func(name, layout, want string) {
  919. got := t.Format(layout)
  920. if want != got {
  921. fmt.Printf(&#34;error: for %q got %q; expected %q\n&#34;, layout, got, want)
  922. return
  923. }
  924. fmt.Printf(&#34;%-15s %q gives %q\n&#34;, name, layout, got)
  925. }
  926. <span class="comment">// Print a header in our output.</span>
  927. fmt.Printf(&#34;\nFormats:\n\n&#34;)
  928. <span class="comment">// A simple starter example.</span>
  929. do(&#34;Basic&#34;, &#34;Mon Jan 2 15:04:05 MST 2006&#34;, &#34;Sat Mar 7 11:06:39 PST 2015&#34;)
  930. <span class="comment">// For fixed-width printing of values, such as the date, that may be one or</span>
  931. <span class="comment">// two characters (7 vs. 07), use an _ instead of a space in the layout string.</span>
  932. <span class="comment">// Here we print just the day, which is 2 in our layout string and 7 in our</span>
  933. <span class="comment">// value.</span>
  934. do(&#34;No pad&#34;, &#34;&lt;2&gt;&#34;, &#34;&lt;7&gt;&#34;)
  935. <span class="comment">// An underscore represents a zero pad, if required.</span>
  936. do(&#34;Spaces&#34;, &#34;&lt;_2&gt;&#34;, &#34;&lt; 7&gt;&#34;)
  937. <span class="comment">// Similarly, a 0 indicates zero padding.</span>
  938. do(&#34;Zeros&#34;, &#34;&lt;02&gt;&#34;, &#34;&lt;07&gt;&#34;)
  939. <span class="comment">// If the value is already the right width, padding is not used.</span>
  940. <span class="comment">// For instance, the second (05 in the reference time) in our value is 39,</span>
  941. <span class="comment">// so it doesn&#39;t need padding, but the minutes (04, 06) does.</span>
  942. do(&#34;Suppressed pad&#34;, &#34;04:05&#34;, &#34;06:39&#34;)
  943. <span class="comment">// The predefined constant Unix uses an underscore to pad the day.</span>
  944. <span class="comment">// Compare with our simple starter example.</span>
  945. do(&#34;Unix&#34;, time.UnixDate, &#34;Sat Mar 7 11:06:39 PST 2015&#34;)
  946. <span class="comment">// The hour of the reference time is 15, or 3PM. The layout can express</span>
  947. <span class="comment">// it either way, and since our value is the morning we should see it as</span>
  948. <span class="comment">// an AM time. We show both in one format string. Lower case too.</span>
  949. do(&#34;AM/PM&#34;, &#34;3PM==3pm==15h&#34;, &#34;11AM==11am==11h&#34;)
  950. <span class="comment">// When parsing, if the seconds value is followed by a decimal point</span>
  951. <span class="comment">// and some digits, that is taken as a fraction of a second even if</span>
  952. <span class="comment">// the layout string does not represent the fractional second.</span>
  953. <span class="comment">// Here we add a fractional second to our time value used above.</span>
  954. t, err = time.Parse(time.UnixDate, &#34;Sat Mar 7 11:06:39.1234 PST 2015&#34;)
  955. if err != nil {
  956. panic(err)
  957. }
  958. <span class="comment">// It does not appear in the output if the layout string does not contain</span>
  959. <span class="comment">// a representation of the fractional second.</span>
  960. do(&#34;No fraction&#34;, time.UnixDate, &#34;Sat Mar 7 11:06:39 PST 2015&#34;)
  961. <span class="comment">// Fractional seconds can be printed by adding a run of 0s or 9s after</span>
  962. <span class="comment">// a decimal point in the seconds value in the layout string.</span>
  963. <span class="comment">// If the layout digits are 0s, the fractional second is of the specified</span>
  964. <span class="comment">// width. Note that the output has a trailing zero.</span>
  965. do(&#34;0s for fraction&#34;, &#34;15:04:05.00000&#34;, &#34;11:06:39.12340&#34;)
  966. <span class="comment">// If the fraction in the layout is 9s, trailing zeros are dropped.</span>
  967. do(&#34;9s for fraction&#34;, &#34;15:04:05.99999999&#34;, &#34;11:06:39.1234&#34;)
  968. <span class="comment"></pre>
  969. <p>Output:</p>
  970. <pre class="output">default format: 2015-03-07 11:06:39 -0800 PST
  971. Unix format: Sat Mar 7 11:06:39 PST 2015
  972. Same, in UTC: Sat Mar 7 19:06:39 UTC 2015
  973. Formats:
  974. Basic &#34;Mon Jan 2 15:04:05 MST 2006&#34; gives &#34;Sat Mar 7 11:06:39 PST 2015&#34;
  975. No pad &#34;&lt;2&gt;&#34; gives &#34;&lt;7&gt;&#34;
  976. Spaces &#34;&lt;_2&gt;&#34; gives &#34;&lt; 7&gt;&#34;
  977. Zeros &#34;&lt;02&gt;&#34; gives &#34;&lt;07&gt;&#34;
  978. Suppressed pad &#34;04:05&#34; gives &#34;06:39&#34;
  979. Unix &#34;Mon Jan _2 15:04:05 MST 2006&#34; gives &#34;Sat Mar 7 11:06:39 PST 2015&#34;
  980. AM/PM &#34;3PM==3pm==15h&#34; gives &#34;11AM==11am==11h&#34;
  981. No fraction &#34;Mon Jan _2 15:04:05 MST 2006&#34; gives &#34;Sat Mar 7 11:06:39 PST 2015&#34;
  982. 0s for fraction &#34;15:04:05.00000&#34; gives &#34;11:06:39.12340&#34;
  983. 9s for fraction &#34;15:04:05.99999999&#34; gives &#34;11:06:39.1234&#34;
  984. </pre>
  985. </div>
  986. </div>
  987. <h3 id="Time.GobDecode">func (*Time) <a href="http://localhost:6060/src/time/time.go?s=26765:26808#L916">GobDecode</a></h3>
  988. <pre>func (t *<a href="index.html#Time">Time</a>) GobDecode(data []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#error">error</a></pre>
  989. <p>
  990. GobDecode implements the gob.GobDecoder interface.
  991. </p>
  992. <h3 id="Time.GobEncode">func (Time) <a href="http://localhost:6060/src/time/time.go?s=26638:26679#L911">GobEncode</a></h3>
  993. <pre>func (t <a href="index.html#Time">Time</a>) GobEncode() ([]<a href="../builtin/index.html#byte">byte</a>, <a href="../builtin/index.html#error">error</a>)</pre>
  994. <p>
  995. GobEncode implements the gob.GobEncoder interface.
  996. </p>
  997. <h3 id="Time.Hour">func (Time) <a href="http://localhost:6060/src/time/time.go?s=12994:13018#L390">Hour</a></h3>
  998. <pre>func (t <a href="index.html#Time">Time</a>) Hour() <a href="../builtin/index.html#int">int</a></pre>
  999. <p>
  1000. Hour returns the hour within the day specified by t, in the range [0, 23].
  1001. </p>
  1002. <h3 id="Time.ISOWeek">func (Time) <a href="http://localhost:6060/src/time/time.go?s=10978:11018#L319">ISOWeek</a></h3>
  1003. <pre>func (t <a href="index.html#Time">Time</a>) ISOWeek() (year, week <a href="../builtin/index.html#int">int</a>)</pre>
  1004. <p>
  1005. ISOWeek returns the ISO 8601 year and week number in which t occurs.
  1006. Week ranges from 1 to 53. Jan 01 to Jan 03 of year n might belong to
  1007. week 52 or 53 of year n-1, and Dec 29 to Dec 31 might belong to week 1
  1008. of year n+1.
  1009. </p>
  1010. <h3 id="Time.In">func (Time) <a href="http://localhost:6060/src/time/time.go?s=23247:23283#L791">In</a></h3>
  1011. <pre>func (t <a href="index.html#Time">Time</a>) In(loc *<a href="index.html#Location">Location</a>) <a href="index.html#Time">Time</a></pre>
  1012. <p>
  1013. In returns t with the location information set to loc.
  1014. </p>
  1015. <p>
  1016. In panics if loc is nil.
  1017. </p>
  1018. <h3 id="Time.IsZero">func (Time) <a href="http://localhost:6060/src/time/time.go?s=8503:8530#L231">IsZero</a></h3>
  1019. <pre>func (t <a href="index.html#Time">Time</a>) IsZero() <a href="../builtin/index.html#bool">bool</a></pre>
  1020. <p>
  1021. IsZero reports whether t represents the zero time instant,
  1022. January 1, year 1, 00:00:00 UTC.
  1023. </p>
  1024. <h3 id="Time.Local">func (Time) <a href="http://localhost:6060/src/time/time.go?s=23101:23127#L783">Local</a></h3>
  1025. <pre>func (t <a href="index.html#Time">Time</a>) Local() <a href="index.html#Time">Time</a></pre>
  1026. <p>
  1027. Local returns t with the location set to local time.
  1028. </p>
  1029. <h3 id="Time.Location">func (Time) <a href="http://localhost:6060/src/time/time.go?s=23450:23484#L800">Location</a></h3>
  1030. <pre>func (t <a href="index.html#Time">Time</a>) Location() *<a href="index.html#Location">Location</a></pre>
  1031. <p>
  1032. Location returns the time zone information associated with t.
  1033. </p>
  1034. <h3 id="Time.MarshalBinary">func (Time) <a href="http://localhost:6060/src/time/time.go?s=24443:24488#L832">MarshalBinary</a></h3>
  1035. <pre>func (t <a href="index.html#Time">Time</a>) MarshalBinary() ([]<a href="../builtin/index.html#byte">byte</a>, <a href="../builtin/index.html#error">error</a>)</pre>
  1036. <p>
  1037. MarshalBinary implements the encoding.BinaryMarshaler interface.
  1038. </p>
  1039. <h3 id="Time.MarshalJSON">func (Time) <a href="http://localhost:6060/src/time/time.go?s=26997:27040#L922">MarshalJSON</a></h3>
  1040. <pre>func (t <a href="index.html#Time">Time</a>) MarshalJSON() ([]<a href="../builtin/index.html#byte">byte</a>, <a href="../builtin/index.html#error">error</a>)</pre>
  1041. <p>
  1042. MarshalJSON implements the json.Marshaler interface.
  1043. The time is a quoted string in RFC 3339 format, with sub-second precision added if present.
  1044. </p>
  1045. <h3 id="Time.MarshalText">func (Time) <a href="http://localhost:6060/src/time/time.go?s=27863:27906#L946">MarshalText</a></h3>
  1046. <pre>func (t <a href="index.html#Time">Time</a>) MarshalText() ([]<a href="../builtin/index.html#byte">byte</a>, <a href="../builtin/index.html#error">error</a>)</pre>
  1047. <p>
  1048. MarshalText implements the encoding.TextMarshaler interface.
  1049. The time is formatted in RFC 3339 format, with sub-second precision added if present.
  1050. </p>
  1051. <h3 id="Time.Minute">func (Time) <a href="http://localhost:6060/src/time/time.go?s=13166:13192#L395">Minute</a></h3>
  1052. <pre>func (t <a href="index.html#Time">Time</a>) Minute() <a href="../builtin/index.html#int">int</a></pre>
  1053. <p>
  1054. Minute returns the minute offset within the hour specified by t, in the range [0, 59].
  1055. </p>
  1056. <h3 id="Time.Month">func (Time) <a href="http://localhost:6060/src/time/time.go?s=10139:10166#L292">Month</a></h3>
  1057. <pre>func (t <a href="index.html#Time">Time</a>) Month() <a href="index.html#Month">Month</a></pre>
  1058. <p>
  1059. Month returns the month of the year specified by t.
  1060. </p>
  1061. <h3 id="Time.Nanosecond">func (Time) <a href="http://localhost:6060/src/time/time.go?s=13527:13557#L406">Nanosecond</a></h3>
  1062. <pre>func (t <a href="index.html#Time">Time</a>) Nanosecond() <a href="../builtin/index.html#int">int</a></pre>
  1063. <p>
  1064. Nanosecond returns the nanosecond offset within the second specified by t,
  1065. in the range [0, 999999999].
  1066. </p>
  1067. <h3 id="Time.Round">func (Time) <a href="http://localhost:6060/src/time/time.go?s=32258:32294#L1103">Round</a></h3>
  1068. <pre>func (t <a href="index.html#Time">Time</a>) Round(d <a href="index.html#Duration">Duration</a>) <a href="index.html#Time">Time</a></pre>
  1069. <p>
  1070. Round returns the result of rounding t to the nearest multiple of d (since the zero time).
  1071. The rounding behavior for halfway values is to round up.
  1072. If d &lt;= 0, Round returns t unchanged.
  1073. </p>
  1074. <div id="example_Time_Round" class="toggle">
  1075. <div class="collapsed">
  1076. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1077. </div>
  1078. <div class="expanded">
  1079. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1080. <p>Code:</p>
  1081. <pre class="code">t := time.Date(0, 0, 0, 12, 15, 30, 918273645, time.UTC)
  1082. round := []time.Duration{
  1083. time.Nanosecond,
  1084. time.Microsecond,
  1085. time.Millisecond,
  1086. time.Second,
  1087. 2 * time.Second,
  1088. time.Minute,
  1089. 10 * time.Minute,
  1090. time.Hour,
  1091. }
  1092. for _, d := range round {
  1093. fmt.Printf(&#34;t.Round(%6s) = %s\n&#34;, d, t.Round(d).Format(&#34;15:04:05.999999999&#34;))
  1094. }
  1095. <span class="comment"></pre>
  1096. <p>Output:</p>
  1097. <pre class="output">t.Round( 1ns) = 12:15:30.918273645
  1098. t.Round( 1µs) = 12:15:30.918274
  1099. t.Round( 1ms) = 12:15:30.918
  1100. t.Round( 1s) = 12:15:31
  1101. t.Round( 2s) = 12:15:30
  1102. t.Round( 1m0s) = 12:16:00
  1103. t.Round( 10m0s) = 12:20:00
  1104. t.Round(1h0m0s) = 12:00:00
  1105. </pre>
  1106. </div>
  1107. </div>
  1108. <h3 id="Time.Second">func (Time) <a href="http://localhost:6060/src/time/time.go?s=13345:13371#L400">Second</a></h3>
  1109. <pre>func (t <a href="index.html#Time">Time</a>) Second() <a href="../builtin/index.html#int">int</a></pre>
  1110. <p>
  1111. Second returns the second offset within the minute specified by t, in the range [0, 59].
  1112. </p>
  1113. <h3 id="Time.String">func (Time) <a href="http://localhost:6060/src/time/format.go?s=12854:12883#L407">String</a></h3>
  1114. <pre>func (t <a href="index.html#Time">Time</a>) String() <a href="../builtin/index.html#string">string</a></pre>
  1115. <p>
  1116. String returns the time formatted using the format string
  1117. </p>
  1118. <pre>&#34;2006-01-02 15:04:05.999999999 -0700 MST&#34;
  1119. </pre>
  1120. <h3 id="Time.Sub">func (Time) <a href="http://localhost:6060/src/time/time.go?s=18822:18856#L618">Sub</a></h3>
  1121. <pre>func (t <a href="index.html#Time">Time</a>) Sub(u <a href="index.html#Time">Time</a>) <a href="index.html#Duration">Duration</a></pre>
  1122. <p>
  1123. Sub returns the duration t-u. If the result exceeds the maximum (or minimum)
  1124. value that can be stored in a Duration, the maximum (or minimum) duration
  1125. will be returned.
  1126. To compute t-d for a duration d, use t.Add(-d).
  1127. </p>
  1128. <h3 id="Time.Truncate">func (Time) <a href="http://localhost:6060/src/time/time.go?s=31954:31993#L1092">Truncate</a></h3>
  1129. <pre>func (t <a href="index.html#Time">Time</a>) Truncate(d <a href="index.html#Duration">Duration</a>) <a href="index.html#Time">Time</a></pre>
  1130. <p>
  1131. Truncate returns the result of rounding t down to a multiple of d (since the zero time).
  1132. If d &lt;= 0, Truncate returns t unchanged.
  1133. </p>
  1134. <div id="example_Time_Truncate" class="toggle">
  1135. <div class="collapsed">
  1136. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1137. </div>
  1138. <div class="expanded">
  1139. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  1140. <p>Code:</p>
  1141. <pre class="code">t, _ := time.Parse(&#34;2006 Jan 02 15:04:05&#34;, &#34;2012 Dec 07 12:15:30.918273645&#34;)
  1142. trunc := []time.Duration{
  1143. time.Nanosecond,
  1144. time.Microsecond,
  1145. time.Millisecond,
  1146. time.Second,
  1147. 2 * time.Second,
  1148. time.Minute,
  1149. 10 * time.Minute,
  1150. time.Hour,
  1151. }
  1152. for _, d := range trunc {
  1153. fmt.Printf(&#34;t.Truncate(%6s) = %s\n&#34;, d, t.Truncate(d).Format(&#34;15:04:05.999999999&#34;))
  1154. }
  1155. <span class="comment"></pre>
  1156. <p>Output:</p>
  1157. <pre class="output">t.Truncate( 1ns) = 12:15:30.918273645
  1158. t.Truncate( 1µs) = 12:15:30.918273
  1159. t.Truncate( 1ms) = 12:15:30.918
  1160. t.Truncate( 1s) = 12:15:30
  1161. t.Truncate( 2s) = 12:15:30
  1162. t.Truncate( 1m0s) = 12:15:00
  1163. t.Truncate( 10m0s) = 12:10:00
  1164. t.Truncate(1h0m0s) = 12:00:00
  1165. </pre>
  1166. </div>
  1167. </div>
  1168. <h3 id="Time.UTC">func (Time) <a href="http://localhost:6060/src/time/time.go?s=22992:23016#L777">UTC</a></h3>
  1169. <pre>func (t <a href="index.html#Time">Time</a>) UTC() <a href="index.html#Time">Time</a></pre>
  1170. <p>
  1171. UTC returns t with the location set to UTC.
  1172. </p>
  1173. <h3 id="Time.Unix">func (Time) <a href="http://localhost:6060/src/time/time.go?s=23909:23935#L817">Unix</a></h3>
  1174. <pre>func (t <a href="index.html#Time">Time</a>) Unix() <a href="../builtin/index.html#int64">int64</a></pre>
  1175. <p>
  1176. Unix returns t as a Unix time, the number of seconds elapsed
  1177. since January 1, 1970 UTC.
  1178. </p>
  1179. <h3 id="Time.UnixNano">func (Time) <a href="http://localhost:6060/src/time/time.go?s=24254:24284#L825">UnixNano</a></h3>
  1180. <pre>func (t <a href="index.html#Time">Time</a>) UnixNano() <a href="../builtin/index.html#int64">int64</a></pre>
  1181. <p>
  1182. UnixNano returns t as a Unix time, the number of nanoseconds elapsed
  1183. since January 1, 1970 UTC. The result is undefined if the Unix time
  1184. in nanoseconds cannot be represented by an int64. Note that this
  1185. means the result of calling UnixNano on the zero Time is undefined.
  1186. </p>
  1187. <h3 id="Time.UnmarshalBinary">func (*Time) <a href="http://localhost:6060/src/time/time.go?s=25444:25493#L871">UnmarshalBinary</a></h3>
  1188. <pre>func (t *<a href="index.html#Time">Time</a>) UnmarshalBinary(data []<a href="../builtin/index.html#byte">byte</a>) <a href="../builtin/index.html#error">error</a></pre>
  1189. <p>
  1190. UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
  1191. </p>
  1192. <h3 id="Time.UnmarshalJSON">func (*Time) <a href="http://localhost:6060/src/time/time.go?s=27539:27592#L938">UnmarshalJSON</a></h3>
  1193. <pre>func (t *<a href="index.html#Time">Time</a>) UnmarshalJSON(data []<a href="../builtin/index.html#byte">byte</a>) (err <a href="../builtin/index.html#error">error</a>)</pre>
  1194. <p>
  1195. UnmarshalJSON implements the json.Unmarshaler interface.
  1196. The time is expected to be a quoted string in RFC 3339 format.
  1197. </p>
  1198. <h3 id="Time.UnmarshalText">func (*Time) <a href="http://localhost:6060/src/time/time.go?s=28236:28289#L957">UnmarshalText</a></h3>
  1199. <pre>func (t *<a href="index.html#Time">Time</a>) UnmarshalText(data []<a href="../builtin/index.html#byte">byte</a>) (err <a href="../builtin/index.html#error">error</a>)</pre>
  1200. <p>
  1201. UnmarshalText implements the encoding.TextUnmarshaler interface.
  1202. The time is expected to be in RFC 3339 format.
  1203. </p>
  1204. <h3 id="Time.Weekday">func (Time) <a href="http://localhost:6060/src/time/time.go?s=10396:10427#L304">Weekday</a></h3>
  1205. <pre>func (t <a href="index.html#Time">Time</a>) Weekday() <a href="index.html#Weekday">Weekday</a></pre>
  1206. <p>
  1207. Weekday returns the day of the week specified by t.
  1208. </p>
  1209. <h3 id="Time.Year">func (Time) <a href="http://localhost:6060/src/time/time.go?s=10009:10033#L286">Year</a></h3>
  1210. <pre>func (t <a href="index.html#Time">Time</a>) Year() <a href="../builtin/index.html#int">int</a></pre>
  1211. <p>
  1212. Year returns the year in which t occurs.
  1213. </p>
  1214. <h3 id="Time.YearDay">func (Time) <a href="http://localhost:6060/src/time/time.go?s=13709:13736#L412">YearDay</a></h3>
  1215. <pre>func (t <a href="index.html#Time">Time</a>) YearDay() <a href="../builtin/index.html#int">int</a></pre>
  1216. <p>
  1217. YearDay returns the day of the year specified by t, in the range [1,365] for non-leap years,
  1218. and [1,366] in leap years.
  1219. </p>
  1220. <h3 id="Time.Zone">func (Time) <a href="http://localhost:6060/src/time/time.go?s=23693:23739#L810">Zone</a></h3>
  1221. <pre>func (t <a href="index.html#Time">Time</a>) Zone() (name <a href="../builtin/index.html#string">string</a>, offset <a href="../builtin/index.html#int">int</a>)</pre>
  1222. <p>
  1223. Zone computes the time zone in effect at time t, returning the abbreviated
  1224. name of the zone (such as &#34;CET&#34;) and its offset in seconds east of UTC.
  1225. </p>
  1226. <h2 id="Timer">type <a href="http://localhost:6060/src/time/sleep.go?s=1447:1499#L37">Timer</a></h2>
  1227. <pre>type Timer struct {
  1228. C &lt;-chan <a href="index.html#Time">Time</a>
  1229. <span class="comment">// contains filtered or unexported fields</span>
  1230. }</pre>
  1231. <p>
  1232. The Timer type represents a single event.
  1233. When the Timer expires, the current time will be sent on C,
  1234. unless the Timer was created by AfterFunc.
  1235. A Timer must be created with NewTimer or AfterFunc.
  1236. </p>
  1237. <h3 id="AfterFunc">func <a href="http://localhost:6060/src/time/sleep.go?s=3243:3286#L106">AfterFunc</a></h3>
  1238. <pre>func AfterFunc(d <a href="index.html#Duration">Duration</a>, f func()) *<a href="index.html#Timer">Timer</a></pre>
  1239. <p>
  1240. AfterFunc waits for the duration to elapse and then calls f
  1241. in its own goroutine. It returns a Timer that can
  1242. be used to cancel the call using its Stop method.
  1243. </p>
  1244. <h3 id="NewTimer">func <a href="http://localhost:6060/src/time/sleep.go?s=1986:2018#L56">NewTimer</a></h3>
  1245. <pre>func NewTimer(d <a href="index.html#Duration">Duration</a>) *<a href="index.html#Timer">Timer</a></pre>
  1246. <p>
  1247. NewTimer creates a new Timer that will send
  1248. the current time on its channel after at least duration d.
  1249. </p>
  1250. <h3 id="Timer.Reset">func (*Timer) <a href="http://localhost:6060/src/time/sleep.go?s=2330:2368#L73">Reset</a></h3>
  1251. <pre>func (t *<a href="index.html#Timer">Timer</a>) Reset(d <a href="index.html#Duration">Duration</a>) <a href="../builtin/index.html#bool">bool</a></pre>
  1252. <p>
  1253. Reset changes the timer to expire after duration d.
  1254. It returns true if the timer had been active, false if the timer had
  1255. expired or been stopped.
  1256. </p>
  1257. <h3 id="Timer.Stop">func (*Timer) <a href="http://localhost:6060/src/time/sleep.go?s=1746:1773#L47">Stop</a></h3>
  1258. <pre>func (t *<a href="index.html#Timer">Timer</a>) Stop() <a href="../builtin/index.html#bool">bool</a></pre>
  1259. <p>
  1260. Stop prevents the Timer from firing.
  1261. It returns true if the call stops the timer, false if the timer has already
  1262. expired or been stopped.
  1263. Stop does not close the channel, to prevent a read from the channel succeeding
  1264. incorrectly.
  1265. </p>
  1266. <h2 id="Weekday">type <a href="http://localhost:6060/src/time/time.go?s=3598:3614#L103">Weekday</a></h2>
  1267. <pre>type Weekday <a href="../builtin/index.html#int">int</a></pre>
  1268. <p>
  1269. A Weekday specifies a day of the week (Sunday = 0, ...).
  1270. </p>
  1271. <pre>const (
  1272. <span id="Sunday">Sunday</span> <a href="index.html#Weekday">Weekday</a> = <a href="../builtin/index.html#iota">iota</a>
  1273. <span id="Monday">Monday</span>
  1274. <span id="Tuesday">Tuesday</span>
  1275. <span id="Wednesday">Wednesday</span>
  1276. <span id="Thursday">Thursday</span>
  1277. <span id="Friday">Friday</span>
  1278. <span id="Saturday">Saturday</span>
  1279. )</pre>
  1280. <h3 id="Weekday.String">func (Weekday) <a href="http://localhost:6060/src/time/time.go?s=3891:3923#L126">String</a></h3>
  1281. <pre>func (d <a href="index.html#Weekday">Weekday</a>) String() <a href="../builtin/index.html#string">string</a></pre>
  1282. <p>
  1283. String returns the English name of the day (&#34;Sunday&#34;, &#34;Monday&#34;, ...).
  1284. </p>
  1285. <div id="footer">
  1286. Build version go1.6.<br>
  1287. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  1288. the content of this page is licensed under the
  1289. Creative Commons Attribution 3.0 License,
  1290. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  1291. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  1292. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  1293. </div>
  1294. </div><!-- .container -->
  1295. </div><!-- #page -->
  1296. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  1297. <script type="text/javascript" src="../../lib/godoc/jquery.js"></script>
  1298. <script type="text/javascript" src="../../lib/godoc/jquery.treeview.js"></script>
  1299. <script type="text/javascript" src="../../lib/godoc/jquery.treeview.edit.js"></script>
  1300. <script type="text/javascript" src="../../lib/godoc/godocs.js"></script>
  1301. </body>
  1302. </html>