Wednesday, 21 February 2018

How to set day of year using withdayOfyear method of ZonedDateTime Class


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

ZoneDateTimeDemo.java

import java.time.ZonedDateTime;

public class ZoneDateTimeDemo
{

    public static void main(String[] args)
    {

        ZonedDateTime zonedDateTime1 = ZonedDateTime
                .parse("2017-02-03T10:15:30+01:00");
     
        System.out.println("zonedDateTime1    = " + zonedDateTime1);
        /*
         * Parameters:
         *
         * dayOfYear - the day-of-year to set in the result, from 1 to
         * 365-366
         *
         * Returns:
         *
         * a ZonedDateTime based on this date with the requested day,
         * not null
         */

        ZonedDateTime zonedDateTime2 = zonedDateTime1.withDayOfYear(150);
        System.out.println("DayOfYear changed = " + zonedDateTime2);

    }

}

Output

zonedDateTime1    = 2017-02-03T10:15:30+01:00
DayOfYear changed = 2017-05-30T10:15:30+01:00

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/914905cc2357de2bddb749208190c8f0bf0f9978/BasicJava/ZoneDateTimeDemo_withdayofyear/?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