Close

Java Date Time - MonthDay.now() Examples

Java Date Time Java Java API 


Class:

java.time.MonthDay

java.lang.Objectjava.lang.Objectjava.time.MonthDayjava.time.MonthDayjava.time.temporal.TemporalAccessorTemporalAccessorjava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Methods:

public static MonthDay now()

Creates and returns the current month-day from the system clock in the default time-zone.



public static MonthDay now(ZoneId zone)

Creates and returns the current month-day from the system clock in the the provided time-zone.



public static MonthDay now(Clock clock)

Creates and returns the month-day from the specified clock.


Examples


package com.logicbig.example.monthday;

import java.time.MonthDay;

public class NowExample {

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

Output

--05-01




package com.logicbig.example.monthday;

import java.time.MonthDay;
import java.time.ZoneId;

public class NowExample2 {

public static void main(String... args) {
ZoneId z = ZoneId.of("Japan");
System.out.println(z);

MonthDay m = MonthDay.now(z);
System.out.println(m);


ZoneId z2 = ZoneId.of("Canada/Central");
System.out.println(z2);

MonthDay m2 = MonthDay.now(z2);
System.out.println(m2);
}
}

Output

Japan
--05-02
Canada/Central
--05-01




package com.logicbig.example.monthday;

import java.time.Clock;
import java.time.Duration;
import java.time.MonthDay;

public class NowExample3 {

public static void main(String... args) {
Clock c = Clock.tick(Clock.systemDefaultZone(), Duration.ofDays(5));
System.out.println(c);

MonthDay m = MonthDay.now(c);
System.out.println(m);
}
}

Output

TickClock[SystemClock[America/Chicago],PT120H]
--04-28




See Also