Java Clock tickMinutes() method in Java with Examples
java.time.Clock.tickMinutes(ZoneId zone) method is a static method of Clock class which returns the current instant ticking in whole minutes using best available system clock and the time-zone of that instant is same as the time-zone passed as a parameter.
Nanosecond and second fields of the clock are set to zero to round the instant in the whole minute. The underlying clock is the best system clock which is same as system (ZoneId). A duration of zero or one nanosecond would have no effect on base clock method. These will return the same base clock.
The returned clock is also immutable, thread-safe and Serializable and this method is equivalent to tick(system(zone), Duration.ofMinutes(1)).
Syntax:
public static Clock tickMinutes(ZoneId zone)
Parameters: This method takes a mandatory parameter zone which is the time-zone used to round off instant of a clock in the whole minute.
Return Value: This method returns a clock that returns the current instant ticking in whole minutes
with zone same as zone passed as parameter.
Example:
Code:
ZoneId zoneId = ZoneId.of("Asia/Calcutta");
Clock clock = Clock.tickMinutes(zoneId);
System.out.println(clock.instant());
Output:
2018-08-21T19:55:00Z
Expalnation::
method tickMinutes() returns the instant
which tick in a whole minute. It means the second
and nanosecond fields are zero, which can be
visualized as the second field is empty in output.
Below programs illustrates tickMinutes() method of java.time.Clock class:
Program 1: When Clock is created with Zone “Asia/Calcutta” for printing instant of clock ticking in whole minute.
// Java program to demonstrate // tickMinutes() method of Clock class import java.time.*; // create class public class GFG { // Main method public static void main(String[] args) { // Zone Id with Zone Asia/Calcutta ZoneId zoneId = ZoneId.of("Asia/Calcutta"); // create clock which ticks in whole minute Clock clock = Clock.tickMinutes(zoneId); // print instance of clock System.out.println(clock.instant()); } } |
2018-08-24T07:51:00Z
Program 2: Print the date and Time of clock with zone “Europe/Paris” and clock ticks per whole minute.
// Java program to demonstrate // tickMinutes() method of Clock class import java.time.*; // create class public class tickMinutesMethodDemo { // Main method public static void main(String[] args) { // Zone Id with Zone Europe/Paris ZoneId zoneId = ZoneId.of("Europe/Paris"); // create clock which ticks in whole minute Clock clock = Clock.tickMinutes(zoneId); // get ZonedDateTime object to print time ZonedDateTime time = clock.instant() .atZone(clock.getZone()); // print time variable value System.out.println("Date and Time :" + time); } } |
Date and Time :2018-08-24T09:52+02:00[Europe/Paris]
Reference:
https://docs.oracle.com/javase/8/docs/api/java/time/Clock.html#tickMinutes-java.time.ZoneId-
Recommended Posts:
- Java Clock withZone() method in Java with Examples
- Clock systemDefaultZone() Method in Java with Examples
- Clock systemUTC() Method in Java with Examples
- Clock system() Method in Java with Examples
- Java 8 Clock millis() Method with Examples
- Clock tickSeconds() method in Java with Examples
- Clock tick() Method in Java with Examples
- Java 8 Clock equals() Method with Examples
- Java 8 Clock getZone() method with Examples
- Java 8 Clock offset() method with Examples
- Java 8 Clock hashCode() method with Examples
- Java 8 Clock instant() method with Examples
- Java 8 Clock fixed() method with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



