Friday, 2 February 2018

How to get current month and day using now methods of MonthDay Class | Java 8 Date and Time


Click here to watch on Youtube : 
https://www.youtube.com/watch?v=qzbUJAQA5rc&list=UUhwKlOVR041tngjerWxVccw

MonthDayDemo1.java

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

public class MonthDayDemo1
{
    public static void main(String[] args)
    {
        Clock clock = Clock.systemUTC();
        System.out.println(clock);
        /*
         * Parameters:
         *
         * clock - the clock to use, not null
         *
         * Returns:
         *
         * the current month-day, not null
         */

        MonthDay monthDay = MonthDay.now(clock);
        System.out.println(monthDay);

    }

}

Output

SystemClock[Z]
--01-23

MonthDayDemo2.java

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

public class MonthDayDemo2
{
    public static void main(String[] args)
    {

        ZoneId zoneId = ZoneId.systemDefault();
        System.out.println(zoneId);
        /*
         * Parameters:
         *
         * zone - the zone ID to use, not null
         *
         * Returns:
         *
         * the current month-day using the system clock, not
         * null
         */

        MonthDay monthDay = MonthDay.now(zoneId);
        System.out.println(monthDay);
    }

}

Output

Asia/Calcutta
--01-23

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/MonthDayDemo_now_clock_zoneid.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/MonthDayDemo_now_clock_zoneid

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/d57185a7bf9e23294d2a9e7b3cf655cc136de202/BasicJava/MonthDayDemo_now_clock_zoneid/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment