Wednesday 28 March 2018

How to use from method of Period Class | Java 8 Date and Time


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

PeriodDemo.java

import java.time.Period;
import java.time.temporal.TemporalAmount;

public class PeriodDemo
{

    public static void main(String[] args)
    {

        TemporalAmount temporalAmount = Period.ofMonths(12);

        /*
         * Obtains an instance of Period from a temporal amount.
         *
         * Parameters:
         *
         * amount - the temporal amount to convert, not null
         *
         * Returns:
         *
         * the equivalent period, not null
         */

        Period period = Period.from(temporalAmount);

        System.out.println(period);

    }

}

Output

P12M

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/PeriodDemo_from.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/PeriodDemo_from

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/b8bbbd8e3fa258805c096cde7ca05dcc526111c2/BasicJava_2018/PeriodDemo_from/?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
  • Cooking Tutorial
  • No comments:

    Post a Comment