Click here to watch on Youtube:
https://www.youtube.com/watch?v=q1QvRDkLDR0&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge:
Java 8 Duration Class Introduction | Java 8 Date and Time | Java Date and Time |
import java.time.Duration;
import java.time.LocalTime;
public class DurationDemo
{
public static void main(String[] args)
{
/*
* Parameters:
*
* startInclusive - the start instant, inclusive, not null
*
* endExclusive - the end instant, exclusive, not null
*
* Returns: a Duration, not null
*
*/
Duration duration = Duration.between(LocalTime.MIDNIGHT,
LocalTime.NOON);
System.out.println("duration = " + duration);
/*
* Returns:the whole seconds part of the length of the
* duration, positive or negative
*/
System.out.println("seconds = " + duration.getSeconds());
/*
* Returns a copy of this duration with a positive length.
*/
System.out.println("abs = " + duration.abs());
}
}
import java.time.LocalTime;
public class DurationDemo
{
public static void main(String[] args)
{
/*
* Parameters:
*
* startInclusive - the start instant, inclusive, not null
*
* endExclusive - the end instant, exclusive, not null
*
* Returns: a Duration, not null
*
*/
Duration duration = Duration.between(LocalTime.MIDNIGHT,
LocalTime.NOON);
System.out.println("duration = " + duration);
/*
* Returns:the whole seconds part of the length of the
* duration, positive or negative
*/
System.out.println("seconds = " + duration.getSeconds());
/*
* Returns a copy of this duration with a positive length.
*/
System.out.println("abs = " + duration.abs());
}
}
Output
duration = PT12H
seconds = 43200
abs = PT12H
seconds = 43200
abs = PT12H
Refer:
https://docs.oracle.com/javase/8/docs/api/index.html?java/time/Duration.html
Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/DurationDemo_Intro.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/DurationDemo_Intro
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/c7899e666996cf29a48ef15f0030404863025004/BasicJava_2018/DurationDemo_Intro/?at=master
See also:
No comments:
Post a Comment