Close

Java Date Time - Year.now() Examples

Java Date Time Java Java API 


Class:

java.time.Year

java.lang.Objectjava.lang.Objectjava.time.Yearjava.time.Yearjava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Methods:

public static Year now()

Obtains the current year from the system clock in the default time-zone.



public static Year now(ZoneId zone)

Obtains the current year from the system clock in the specified time-zone.



public static Year now(Clock clock)

Obtains the current year from the specified clock.


Examples


package com.logicbig.example.year;

import java.time.Year;

public class NowExample {

public static void main(String... args) {
Year y = Year.now();
System.out.println(y);
}
}

Output

2017




package com.logicbig.example.year;

import java.time.Year;
import java.time.ZoneId;

public class NowExample2 {

public static void main(String... args) {
Year y = Year.now(ZoneId.of("US/Hawaii"));
System.out.println(y);
}
}

Output

2017




package com.logicbig.example.year;

import java.time.Clock;
import java.time.Year;
import java.time.ZoneId;

public class NowExample3 {

public static void main(String... args) {

Clock c = Clock.tickMinutes(ZoneId.of("Asia/Manila"));
Year y = Year.now(c);
System.out.println(y);
}
}

Output

2017




See Also