forked from bjmashibing/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.html
More file actions
873 lines (873 loc) · 41.1 KB
/
Clock.html
File metadata and controls
873 lines (873 loc) · 41.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
<!DOCTYPE HTML>
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc -->
<title>Clock (Java SE 12 & JDK 12 )</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="java.time.Clock class">
<meta name="keywords" content="systemUTC()">
<meta name="keywords" content="systemDefaultZone()">
<meta name="keywords" content="system()">
<meta name="keywords" content="tickMillis()">
<meta name="keywords" content="tickSeconds()">
<meta name="keywords" content="tickMinutes()">
<meta name="keywords" content="tick()">
<meta name="keywords" content="fixed()">
<meta name="keywords" content="offset()">
<meta name="keywords" content="getZone()">
<meta name="keywords" content="withZone()">
<meta name="keywords" content="millis()">
<meta name="keywords" content="instant()">
<meta name="keywords" content="equals()">
<meta name="keywords" content="hashCode()">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
<script type="text/javascript" src="../../../jquery/jszip/dist/jszip.min.js"></script>
<script type="text/javascript" src="../../../jquery/jszip-utils/dist/jszip-utils.min.js"></script>
<!--[if IE]>
<script type="text/javascript" src="../../../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script>
<![endif]-->
<script type="text/javascript" src="../../../jquery/jquery-3.3.1.js"></script>
<script type="text/javascript" src="../../../jquery/jquery-migrate-3.0.1.js"></script>
<script type="text/javascript" src="../../../jquery/jquery-ui.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Clock (Java SE 12 & JDK 12 )";
}
}
catch(err) {
}
//-->
var data = {"i0":10,"i1":9,"i2":6,"i3":10,"i4":6,"i5":10,"i6":9,"i7":9,"i8":9,"i9":9,"i10":9,"i11":9,"i12":9,"i13":9,"i14":6};
var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
var pathtoroot = "../../../";
var useModuleDirectories = true;
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<header role="banner">
<nav role="navigation">
<div class="fixedNav">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a id="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../index.html">Overview</a></li>
<li><a href="../../module-summary.html">Module</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/Clock.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../index-files/index-1.html">Index</a></li>
<li><a href="../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage"><div style="margin-top: 14px;"><strong>Java SE 12 & JDK 12</strong> </div></div>
</div>
<div class="subNav">
<div>
<ul class="subNavList">
<li>Summary: </li>
<li>Nested | </li>
<li>Field | </li>
<li><a href="#constructor.summary">Constr</a> | </li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail: </li>
<li>Field | </li>
<li><a href="#constructor.detail">Constr</a> | </li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<ul class="navListSearch">
<li><label for="search">SEARCH:</label>
<input type="text" id="search" value="search" disabled="disabled">
<input type="reset" id="reset" value="reset" disabled="disabled">
</li>
</ul>
</div>
<a id="skip.navbar.top">
<!-- -->
</a>
<!-- ========= END OF TOP NAVBAR ========= -->
</div>
<div class="navPadding"> </div>
<script type="text/javascript"><!--
$('.navPadding').css('padding-top', $('.fixedNav').css("height"));
//-->
</script>
</nav>
</header>
<!-- ======== START OF CLASS DATA ======== -->
<main role="main">
<div class="header">
<div class="subTitle"><span class="moduleLabelInType">Module</span> <a href="../../module-summary.html">java.base</a></div>
<div class="subTitle"><span class="packageLabelInType">Package</span> <a href="package-summary.html">java.time</a></div>
<h2 title="Class Clock" class="title">Class Clock</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li><a href="../lang/Object.html" title="class in java.lang">java.lang.Object</a></li>
<li>
<ul class="inheritance">
<li>java.time.Clock</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<pre>public abstract class <span class="typeNameLabel">Clock</span>
extends <a href="../lang/Object.html" title="class in java.lang">Object</a></pre>
<div class="block">A clock providing access to the current instant, date and time using a time-zone.
<p>
Instances of this class are used to find the current instant, which can be
interpreted using the stored time-zone to find the current date and time.
As such, a clock can be used instead of <a href="../lang/System.html#currentTimeMillis()"><code>System.currentTimeMillis()</code></a>
and <a href="../util/TimeZone.html#getDefault()"><code>TimeZone.getDefault()</code></a>.
<p>
Use of a <code>Clock</code> is optional. All key date-time classes also have a
<code>now()</code> factory method that uses the system clock in the default time zone.
The primary purpose of this abstraction is to allow alternate clocks to be
plugged in as and when required. Applications use an object to obtain the
current time rather than a static method. This can simplify testing.
<p>
Best practice for applications is to pass a <code>Clock</code> into any method
that requires the current instant. A dependency injection framework is one
way to achieve this:
<pre>
public class MyBean {
private Clock clock; // dependency inject
...
public void process(LocalDate eventDate) {
if (eventDate.isBefore(LocalDate.now(clock)) {
...
}
}
}
</pre>
This approach allows an alternate clock, such as <a href="#fixed(java.time.Instant,java.time.ZoneId)"><code>fixed</code></a>
or <a href="#offset(java.time.Clock,java.time.Duration)"><code>offset</code></a> to be used during testing.
<p>
The <code>system</code> factory methods provide clocks based on the best available
system clock This may use <a href="../lang/System.html#currentTimeMillis()"><code>System.currentTimeMillis()</code></a>, or a higher
resolution clock if one is available.</div>
<dl>
<dt><span class="simpleTagLabel">Implementation Requirements:</span></dt>
<dd>This abstract class must be implemented with care to ensure other classes operate correctly.
All implementations that can be instantiated must be final, immutable and thread-safe.
<p>
The principal methods are defined to allow the throwing of an exception.
In normal use, no exceptions will be thrown, however one possible implementation would be to
obtain the time from a central time server across the network. Obviously, in this case the
lookup could fail, and so the method is permitted to throw an exception.
<p>
The returned instants from <code>Clock</code> work on a time-scale that ignores leap seconds,
as described in <a href="Instant.html" title="class in java.time"><code>Instant</code></a>. If the implementation wraps a source that provides leap
second information, then a mechanism should be used to "smooth" the leap second.
The Java Time-Scale mandates the use of UTC-SLS, however clock implementations may choose
how accurate they are with the time-scale so long as they document how they work.
Implementations are therefore not required to actually perform the UTC-SLS slew or to
otherwise be aware of leap seconds.
<p>
Implementations should implement <code>Serializable</code> wherever possible and must
document whether or not they do support serialization.</dd>
<dt><span class="simpleTagLabel">Implementation Note:</span></dt>
<dd>The clock implementation provided here is based on the same underlying clock
as <a href="../lang/System.html#currentTimeMillis()"><code>System.currentTimeMillis()</code></a>, but may have a precision finer than
milliseconds if available.
However, little to no guarantee is provided about the accuracy of the
underlying clock. Applications requiring a more accurate clock must implement
this abstract class themselves using a different external clock, such as an
NTP server.</dd>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>1.8</dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="constructor.summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<div class="memberSummary">
<table>
<caption><span>Constructors</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Modifier</th>
<th class="colSecond" scope="col">Constructor</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><code>protected </code></td>
<th class="colConstructorName" scope="row"><code><span class="memberNameLink"><a href="#%3Cinit%3E()">Clock</a></span>()</code></th>
<td class="colLast">
<div class="block">Constructor accessible by subclasses.</div>
</td>
</tr>
</tbody>
</table>
</div>
</li>
</ul>
</section>
<!-- ========== METHOD SUMMARY =========== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<div class="memberSummary">
<div role="tablist" aria-orientation="horizontal"><button role="tab" aria-selected="true" aria-controls="memberSummary_tabpanel" tabindex="0" onkeydown="switchTab(event)" id="t0" class="activeTableTab">All Methods</button><button role="tab" aria-selected="false" aria-controls="memberSummary_tabpanel" tabindex="-1" onkeydown="switchTab(event)" id="t1" class="tableTab" onclick="show(1);">Static Methods</button><button role="tab" aria-selected="false" aria-controls="memberSummary_tabpanel" tabindex="-1" onkeydown="switchTab(event)" id="t2" class="tableTab" onclick="show(2);">Instance Methods</button><button role="tab" aria-selected="false" aria-controls="memberSummary_tabpanel" tabindex="-1" onkeydown="switchTab(event)" id="t3" class="tableTab" onclick="show(4);">Abstract Methods</button><button role="tab" aria-selected="false" aria-controls="memberSummary_tabpanel" tabindex="-1" onkeydown="switchTab(event)" id="t4" class="tableTab" onclick="show(8);">Concrete Methods</button></div>
<div id="memberSummary_tabpanel" role="tabpanel">
<table aria-labelledby="t0">
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colSecond" scope="col">Method</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor" id="i0">
<td class="colFirst"><code>boolean</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#equals(java.lang.Object)">equals</a></span>​(<a href="../lang/Object.html" title="class in java.lang">Object</a> obj)</code></th>
<td class="colLast">
<div class="block">Checks if this clock is equal to another clock.</div>
</td>
</tr>
<tr class="rowColor" id="i1">
<td class="colFirst"><code>static <a href="Clock.html" title="class in java.time">Clock</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#fixed(java.time.Instant,java.time.ZoneId)">fixed</a></span>​(<a href="Instant.html" title="class in java.time">Instant</a> fixedInstant,
<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</code></th>
<td class="colLast">
<div class="block">Obtains a clock that always returns the same instant.</div>
</td>
</tr>
<tr class="altColor" id="i2">
<td class="colFirst"><code>abstract <a href="ZoneId.html" title="class in java.time">ZoneId</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getZone()">getZone</a></span>()</code></th>
<td class="colLast">
<div class="block">Gets the time-zone being used to create dates and times.</div>
</td>
</tr>
<tr class="rowColor" id="i3">
<td class="colFirst"><code>int</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#hashCode()">hashCode</a></span>()</code></th>
<td class="colLast">
<div class="block">A hash code for this clock.</div>
</td>
</tr>
<tr class="altColor" id="i4">
<td class="colFirst"><code>abstract <a href="Instant.html" title="class in java.time">Instant</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#instant()">instant</a></span>()</code></th>
<td class="colLast">
<div class="block">Gets the current instant of the clock.</div>
</td>
</tr>
<tr class="rowColor" id="i5">
<td class="colFirst"><code>long</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#millis()">millis</a></span>()</code></th>
<td class="colLast">
<div class="block">Gets the current millisecond instant of the clock.</div>
</td>
</tr>
<tr class="altColor" id="i6">
<td class="colFirst"><code>static <a href="Clock.html" title="class in java.time">Clock</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#offset(java.time.Clock,java.time.Duration)">offset</a></span>​(<a href="Clock.html" title="class in java.time">Clock</a> baseClock,
<a href="Duration.html" title="class in java.time">Duration</a> offsetDuration)</code></th>
<td class="colLast">
<div class="block">Obtains a clock that returns instants from the specified clock with the
specified duration added</div>
</td>
</tr>
<tr class="rowColor" id="i7">
<td class="colFirst"><code>static <a href="Clock.html" title="class in java.time">Clock</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#system(java.time.ZoneId)">system</a></span>​(<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</code></th>
<td class="colLast">
<div class="block">Obtains a clock that returns the current instant using the best available
system clock.</div>
</td>
</tr>
<tr class="altColor" id="i8">
<td class="colFirst"><code>static <a href="Clock.html" title="class in java.time">Clock</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#systemDefaultZone()">systemDefaultZone</a></span>()</code></th>
<td class="colLast">
<div class="block">Obtains a clock that returns the current instant using the best available
system clock, converting to date and time using the default time-zone.</div>
</td>
</tr>
<tr class="rowColor" id="i9">
<td class="colFirst"><code>static <a href="Clock.html" title="class in java.time">Clock</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#systemUTC()">systemUTC</a></span>()</code></th>
<td class="colLast">
<div class="block">Obtains a clock that returns the current instant using the best available
system clock, converting to date and time using the UTC time-zone.</div>
</td>
</tr>
<tr class="altColor" id="i10">
<td class="colFirst"><code>static <a href="Clock.html" title="class in java.time">Clock</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#tick(java.time.Clock,java.time.Duration)">tick</a></span>​(<a href="Clock.html" title="class in java.time">Clock</a> baseClock,
<a href="Duration.html" title="class in java.time">Duration</a> tickDuration)</code></th>
<td class="colLast">
<div class="block">Obtains a clock that returns instants from the specified clock truncated
to the nearest occurrence of the specified duration.</div>
</td>
</tr>
<tr class="rowColor" id="i11">
<td class="colFirst"><code>static <a href="Clock.html" title="class in java.time">Clock</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#tickMillis(java.time.ZoneId)">tickMillis</a></span>​(<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</code></th>
<td class="colLast">
<div class="block">Obtains a clock that returns the current instant ticking in whole milliseconds
using the best available system clock.</div>
</td>
</tr>
<tr class="altColor" id="i12">
<td class="colFirst"><code>static <a href="Clock.html" title="class in java.time">Clock</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#tickMinutes(java.time.ZoneId)">tickMinutes</a></span>​(<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</code></th>
<td class="colLast">
<div class="block">Obtains a clock that returns the current instant ticking in whole minutes
using the best available system clock.</div>
</td>
</tr>
<tr class="rowColor" id="i13">
<td class="colFirst"><code>static <a href="Clock.html" title="class in java.time">Clock</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#tickSeconds(java.time.ZoneId)">tickSeconds</a></span>​(<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</code></th>
<td class="colLast">
<div class="block">Obtains a clock that returns the current instant ticking in whole seconds
using the best available system clock.</div>
</td>
</tr>
<tr class="altColor" id="i14">
<td class="colFirst"><code>abstract <a href="Clock.html" title="class in java.time">Clock</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#withZone(java.time.ZoneId)">withZone</a></span>​(<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</code></th>
<td class="colLast">
<div class="block">Returns a copy of this clock with a different time-zone.</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<ul class="blockList">
<li class="blockList"><a id="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods declared in class java.lang.<a href="../lang/Object.html" title="class in java.lang">Object</a></h3>
<code><a href="../lang/Object.html#clone()">clone</a>, <a href="../lang/Object.html#finalize()">finalize</a>, <a href="../lang/Object.html#getClass()">getClass</a>, <a href="../lang/Object.html#notify()">notify</a>, <a href="../lang/Object.html#notifyAll()">notifyAll</a>, <a href="../lang/Object.html#toString()">toString</a>, <a href="../lang/Object.html#wait()">wait</a>, <a href="../lang/Object.html#wait(long)">wait</a>, <a href="../lang/Object.html#wait(long,int)">wait</a></code></li>
</ul>
</li>
</ul>
</section>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="constructor.detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a id="<init>()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>Clock</h4>
<pre>protected Clock()</pre>
<div class="block">Constructor accessible by subclasses.</div>
</li>
</ul>
</li>
</ul>
</section>
<!-- ============ METHOD DETAIL ========== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a id="systemUTC()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>systemUTC</h4>
<pre class="methodSignature">public static <a href="Clock.html" title="class in java.time">Clock</a> systemUTC()</pre>
<div class="block">Obtains a clock that returns the current instant using the best available
system clock, converting to date and time using the UTC time-zone.
<p>
This clock, rather than <a href="#systemDefaultZone()"><code>systemDefaultZone()</code></a>, should be used when
you need the current instant without the date or time.
<p>
This clock is based on the best available system clock.
This may use <a href="../lang/System.html#currentTimeMillis()"><code>System.currentTimeMillis()</code></a>, or a higher resolution
clock if one is available.
<p>
Conversion from instant to date or time uses the <a href="ZoneOffset.html#UTC">UTC time-zone</a>.
<p>
The returned implementation is immutable, thread-safe and <code>Serializable</code>.
It is equivalent to <code>system(ZoneOffset.UTC)</code>.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a clock that uses the best available system clock in the UTC zone, not null</dd>
</dl>
</li>
</ul>
<a id="systemDefaultZone()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>systemDefaultZone</h4>
<pre class="methodSignature">public static <a href="Clock.html" title="class in java.time">Clock</a> systemDefaultZone()</pre>
<div class="block">Obtains a clock that returns the current instant using the best available
system clock, converting to date and time using the default time-zone.
<p>
This clock is based on the best available system clock.
This may use <a href="../lang/System.html#currentTimeMillis()"><code>System.currentTimeMillis()</code></a>, or a higher resolution
clock if one is available.
<p>
Using this method hard codes a dependency to the default time-zone into your application.
It is recommended to avoid this and use a specific time-zone whenever possible.
The <a href="#systemUTC()"><code>UTC clock</code></a> should be used when you need the current instant
without the date or time.
<p>
The returned implementation is immutable, thread-safe and <code>Serializable</code>.
It is equivalent to <code>system(ZoneId.systemDefault())</code>.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a clock that uses the best available system clock in the default zone, not null</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="ZoneId.html#systemDefault()"><code>ZoneId.systemDefault()</code></a></dd>
</dl>
</li>
</ul>
<a id="system(java.time.ZoneId)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>system</h4>
<pre class="methodSignature">public static <a href="Clock.html" title="class in java.time">Clock</a> system​(<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</pre>
<div class="block">Obtains a clock that returns the current instant using the best available
system clock.
<p>
This clock is based on the best available system clock.
This may use <a href="../lang/System.html#currentTimeMillis()"><code>System.currentTimeMillis()</code></a>, or a higher resolution
clock if one is available.
<p>
Conversion from instant to date or time uses the specified time-zone.
<p>
The returned implementation is immutable, thread-safe and <code>Serializable</code>.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>zone</code> - the time-zone to use to convert the instant to date-time, not null</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a clock that uses the best available system clock in the specified zone, not null</dd>
</dl>
</li>
</ul>
<a id="tickMillis(java.time.ZoneId)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>tickMillis</h4>
<pre class="methodSignature">public static <a href="Clock.html" title="class in java.time">Clock</a> tickMillis​(<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</pre>
<div class="block">Obtains a clock that returns the current instant ticking in whole milliseconds
using the best available system clock.
<p>
This clock will always have the nano-of-second field truncated to milliseconds.
This ensures that the visible time ticks in whole milliseconds.
The underlying clock is the best available system clock, equivalent to
using <a href="#system(java.time.ZoneId)"><code>system(ZoneId)</code></a>.
<p>
Implementations may use a caching strategy for performance reasons.
As such, it is possible that the start of the millisecond observed via this
clock will be later than that observed directly via the underlying clock.
<p>
The returned implementation is immutable, thread-safe and <code>Serializable</code>.
It is equivalent to <code>tick(system(zone), Duration.ofMillis(1))</code>.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>zone</code> - the time-zone to use to convert the instant to date-time, not null</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a clock that ticks in whole milliseconds using the specified zone, not null</dd>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>9</dd>
</dl>
</li>
</ul>
<a id="tickSeconds(java.time.ZoneId)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>tickSeconds</h4>
<pre class="methodSignature">public static <a href="Clock.html" title="class in java.time">Clock</a> tickSeconds​(<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</pre>
<div class="block">Obtains a clock that returns the current instant ticking in whole seconds
using the best available system clock.
<p>
This clock will always have the nano-of-second field set to zero.
This ensures that the visible time ticks in whole seconds.
The underlying clock is the best available system clock, equivalent to
using <a href="#system(java.time.ZoneId)"><code>system(ZoneId)</code></a>.
<p>
Implementations may use a caching strategy for performance reasons.
As such, it is possible that the start of the second observed via this
clock will be later than that observed directly via the underlying clock.
<p>
The returned implementation is immutable, thread-safe and <code>Serializable</code>.
It is equivalent to <code>tick(system(zone), Duration.ofSeconds(1))</code>.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>zone</code> - the time-zone to use to convert the instant to date-time, not null</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a clock that ticks in whole seconds using the specified zone, not null</dd>
</dl>
</li>
</ul>
<a id="tickMinutes(java.time.ZoneId)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>tickMinutes</h4>
<pre class="methodSignature">public static <a href="Clock.html" title="class in java.time">Clock</a> tickMinutes​(<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</pre>
<div class="block">Obtains a clock that returns the current instant ticking in whole minutes
using the best available system clock.
<p>
This clock will always have the nano-of-second and second-of-minute fields set to zero.
This ensures that the visible time ticks in whole minutes.
The underlying clock is the best available system clock, equivalent to
using <a href="#system(java.time.ZoneId)"><code>system(ZoneId)</code></a>.
<p>
Implementations may use a caching strategy for performance reasons.
As such, it is possible that the start of the minute observed via this
clock will be later than that observed directly via the underlying clock.
<p>
The returned implementation is immutable, thread-safe and <code>Serializable</code>.
It is equivalent to <code>tick(system(zone), Duration.ofMinutes(1))</code>.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>zone</code> - the time-zone to use to convert the instant to date-time, not null</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a clock that ticks in whole minutes using the specified zone, not null</dd>
</dl>
</li>
</ul>
<a id="tick(java.time.Clock,java.time.Duration)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>tick</h4>
<pre class="methodSignature">public static <a href="Clock.html" title="class in java.time">Clock</a> tick​(<a href="Clock.html" title="class in java.time">Clock</a> baseClock,
<a href="Duration.html" title="class in java.time">Duration</a> tickDuration)</pre>
<div class="block">Obtains a clock that returns instants from the specified clock truncated
to the nearest occurrence of the specified duration.
<p>
This clock will only tick as per the specified duration. Thus, if the duration
is half a second, the clock will return instants truncated to the half second.
<p>
The tick duration must be positive. If it has a part smaller than a whole
millisecond, then the whole duration must divide into one second without
leaving a remainder. All normal tick durations will match these criteria,
including any multiple of hours, minutes, seconds and milliseconds, and
sensible nanosecond durations, such as 20ns, 250,000ns and 500,000ns.
<p>
A duration of zero or one nanosecond would have no truncation effect.
Passing one of these will return the underlying clock.
<p>
Implementations may use a caching strategy for performance reasons.
As such, it is possible that the start of the requested duration observed
via this clock will be later than that observed directly via the underlying clock.
<p>
The returned implementation is immutable, thread-safe and <code>Serializable</code>
providing that the base clock is.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>baseClock</code> - the base clock to base the ticking clock on, not null</dd>
<dd><code>tickDuration</code> - the duration of each visible tick, not negative, not null</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a clock that ticks in whole units of the duration, not null</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="../lang/IllegalArgumentException.html" title="class in java.lang">IllegalArgumentException</a></code> - if the duration is negative, or has a
part smaller than a whole millisecond such that the whole duration is not
divisible into one second</dd>
<dd><code><a href="../lang/ArithmeticException.html" title="class in java.lang">ArithmeticException</a></code> - if the duration is too large to be represented as nanos</dd>
</dl>
</li>
</ul>
<a id="fixed(java.time.Instant,java.time.ZoneId)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>fixed</h4>
<pre class="methodSignature">public static <a href="Clock.html" title="class in java.time">Clock</a> fixed​(<a href="Instant.html" title="class in java.time">Instant</a> fixedInstant,
<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</pre>
<div class="block">Obtains a clock that always returns the same instant.
<p>
This clock simply returns the specified instant.
As such, it is not a clock in the conventional sense.
The main use case for this is in testing, where the fixed clock ensures
tests are not dependent on the current clock.
<p>
The returned implementation is immutable, thread-safe and <code>Serializable</code>.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>fixedInstant</code> - the instant to use as the clock, not null</dd>
<dd><code>zone</code> - the time-zone to use to convert the instant to date-time, not null</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a clock that always returns the same instant, not null</dd>
</dl>
</li>
</ul>
<a id="offset(java.time.Clock,java.time.Duration)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>offset</h4>
<pre class="methodSignature">public static <a href="Clock.html" title="class in java.time">Clock</a> offset​(<a href="Clock.html" title="class in java.time">Clock</a> baseClock,
<a href="Duration.html" title="class in java.time">Duration</a> offsetDuration)</pre>
<div class="block">Obtains a clock that returns instants from the specified clock with the
specified duration added
<p>
This clock wraps another clock, returning instants that are later by the
specified duration. If the duration is negative, the instants will be
earlier than the current date and time.
The main use case for this is to simulate running in the future or in the past.
<p>
A duration of zero would have no offsetting effect.
Passing zero will return the underlying clock.
<p>
The returned implementation is immutable, thread-safe and <code>Serializable</code>
providing that the base clock is.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>baseClock</code> - the base clock to add the duration to, not null</dd>
<dd><code>offsetDuration</code> - the duration to add, not null</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a clock based on the base clock with the duration added, not null</dd>
</dl>
</li>
</ul>
<a id="getZone()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getZone</h4>
<pre class="methodSignature">public abstract <a href="ZoneId.html" title="class in java.time">ZoneId</a> getZone()</pre>
<div class="block">Gets the time-zone being used to create dates and times.
<p>
A clock will typically obtain the current instant and then convert that
to a date or time using a time-zone. This method returns the time-zone used.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the time-zone being used to interpret instants, not null</dd>
</dl>
</li>
</ul>
<a id="withZone(java.time.ZoneId)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>withZone</h4>
<pre class="methodSignature">public abstract <a href="Clock.html" title="class in java.time">Clock</a> withZone​(<a href="ZoneId.html" title="class in java.time">ZoneId</a> zone)</pre>
<div class="block">Returns a copy of this clock with a different time-zone.
<p>
A clock will typically obtain the current instant and then convert that
to a date or time using a time-zone. This method returns a clock with
similar properties but using a different time-zone.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>zone</code> - the time-zone to change to, not null</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a clock based on this clock with the specified time-zone, not null</dd>
</dl>
</li>
</ul>
<a id="millis()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>millis</h4>
<pre class="methodSignature">public long millis()</pre>
<div class="block">Gets the current millisecond instant of the clock.
<p>
This returns the millisecond-based instant, measured from 1970-01-01T00:00Z (UTC).
This is equivalent to the definition of <a href="../lang/System.html#currentTimeMillis()"><code>System.currentTimeMillis()</code></a>.
<p>
Most applications should avoid this method and use <a href="Instant.html" title="class in java.time"><code>Instant</code></a> to represent
an instant on the time-line rather than a raw millisecond value.
This method is provided to allow the use of the clock in high performance use cases
where the creation of an object would be unacceptable.
<p>
The default implementation currently calls <a href="#instant()"><code>instant()</code></a>.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the current millisecond instant from this clock, measured from
the Java epoch of 1970-01-01T00:00Z (UTC), not null</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="DateTimeException.html" title="class in java.time">DateTimeException</a></code> - if the instant cannot be obtained, not thrown by most implementations</dd>
</dl>
</li>
</ul>
<a id="instant()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>instant</h4>
<pre class="methodSignature">public abstract <a href="Instant.html" title="class in java.time">Instant</a> instant()</pre>
<div class="block">Gets the current instant of the clock.
<p>
This returns an instant representing the current instant as defined by the clock.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the current instant from this clock, not null</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="DateTimeException.html" title="class in java.time">DateTimeException</a></code> - if the instant cannot be obtained, not thrown by most implementations</dd>
</dl>
</li>
</ul>
<a id="equals(java.lang.Object)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>equals</h4>
<pre class="methodSignature">public boolean equals​(<a href="../lang/Object.html" title="class in java.lang">Object</a> obj)</pre>
<div class="block">Checks if this clock is equal to another clock.
<p>
Clocks should override this method to compare equals based on
their state and to meet the contract of <a href="../lang/Object.html#equals(java.lang.Object)"><code>Object.equals(java.lang.Object)</code></a>.
If not overridden, the behavior is defined by <a href="../lang/Object.html#equals(java.lang.Object)"><code>Object.equals(java.lang.Object)</code></a></div>
<dl>
<dt><span class="overrideSpecifyLabel">Overrides:</span></dt>
<dd><code><a href="../lang/Object.html#equals(java.lang.Object)">equals</a></code> in class <code><a href="../lang/Object.html" title="class in java.lang">Object</a></code></dd>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>obj</code> - the object to check, null returns false</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>true if this is equal to the other clock</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../lang/Object.html#hashCode()"><code>Object.hashCode()</code></a>,
<a href="../util/HashMap.html" title="class in java.util"><code>HashMap</code></a></dd>
</dl>
</li>
</ul>
<a id="hashCode()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>hashCode</h4>
<pre class="methodSignature">public int hashCode()</pre>
<div class="block">A hash code for this clock.
<p>
Clocks should override this method based on
their state and to meet the contract of <a href="../lang/Object.html#hashCode()"><code>Object.hashCode()</code></a>.
If not overridden, the behavior is defined by <a href="../lang/Object.html#hashCode()"><code>Object.hashCode()</code></a></div>
<dl>
<dt><span class="overrideSpecifyLabel">Overrides:</span></dt>
<dd><code><a href="../lang/Object.html#hashCode()">hashCode</a></code> in class <code><a href="../lang/Object.html" title="class in java.lang">Object</a></code></dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a suitable hash code</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../lang/Object.html#equals(java.lang.Object)"><code>Object.equals(java.lang.Object)</code></a>,
<a href="../lang/System.html#identityHashCode(java.lang.Object)"><code>System.identityHashCode(java.lang.Object)</code></a></dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
</li>
</ul>
</div>
</div>
</main>
<!-- ========= END OF CLASS DATA ========= -->
<footer role="contentinfo">
<nav role="navigation">
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a id="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../index.html">Overview</a></li>
<li><a href="../../module-summary.html">Module</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/Clock.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../index-files/index-1.html">Index</a></li>
<li><a href="../../../help-doc.html">Help</a></li>
</ul>
<div class="aboutLanguage"><div style="margin-top: 14px;"><strong>Java SE 12 & JDK 12</strong> </div></div>
</div>
<div class="subNav">
<div>
<ul class="subNavList">
<li>Summary: </li>
<li>Nested | </li>
<li>Field | </li>
<li><a href="#constructor.summary">Constr</a> | </li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail: </li>
<li>Field | </li>
<li><a href="#constructor.detail">Constr</a> | </li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
</div>
<a id="skip.navbar.bottom">
<!-- -->
</a>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</nav>
<p class="legalCopy"><small><a href="https://bugreport.java.com/bugreport/">Report a bug or suggest an enhancement</a><br> For further API reference and developer documentation see the <a href="https://docs.oracle.com/pls/topic/lookup?ctx=javase12.0.2&id=homepage" target="_blank">Java SE Documentation</a>, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.<br> Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.<br> <a href="../../../../legal/copyright.html">Copyright</a> © 1993, 2019, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.<br>All rights reserved. Use is subject to <a href="https://www.oracle.com/technetwork/java/javase/terms/license/java12.0.2speclicense.html">license terms</a> and the <a href="https://www.oracle.com/technetwork/java/redist-137594.html">documentation redistribution policy</a>. <!-- Version 12.0.2+10 --></small></p>
</footer>
</body>
</html>