Beruflich Dokumente
Kultur Dokumente
Prefixes like of, from , plus etc are used before to perform calculations as:
_______________________________________________
LocalDate dob=LocalDate.of(2012,Month.May,14);
LocalDatesSecondBday=dob.plusYears(2);
_________________________________________________
In dealing with dates and times, ISO 8601 standards are used. According to these
standards, we can represent the date and time in the following format.
_________________________________
yyyy-mm-ddTHH:MM:SS.SSS
LocalDate today=LocalDate.now();
_____________________________________________________________________________
Program2:
Write a program to retrieve the date and time is parts separately
import java.time.*;
class Prog2{
public static void main(String args[]){
//Current date is returned by LocalDate.now();
LocalDate date=LocalDate.now();
System.out.printf("\n%d:%d:%d",h,m,s,n);
}
_________________________________________________________________________________
Program: Write a program to create LocalDateTime class object and extract some data
from that object using methods
__________________________________________________________________________________
//LocalDateTime Class
//To display system date and time and get some data
import java.time.*;
class Prog3{
public static void main(String args[]){
//get the current date and time
LocalDateTime dt=LocalDateTime.now();
LocalDateTime dt1=LocalDateTime.of(1994,Month.APRIL,15,11,30);
//Find out the date and time from 6 before from now
//get the day of week for the current date and time
DayOfWeek dw=dt.getDayOfWeek();
import java.time.*;
class Prog4{
public static void main(String args[]){
/* get the default timezoe. If this program is executec in
India then the default timezone
represents India */
ZoneId zone=ZoneId.systemDefault();
System.out.printf("%nCurrentZone =%s ",zone);
}
}
___________________________________________________________________________________
__
Program 5:
Write a program to know the number of days between your birthday and today
___________________________________________________________________________________
//Period class
//To know number days between two dates
import java.time.*;
class Prog5{
public static void main(String args[]){
//get todays date
LocalDate today=LocalDate.now();
___________________________________________________________________________________
_
Program 6:
Write a program to test whether a given year is leap year or not
______________________________________________________
//Year class
//To know whether a year is leap or not
import java.time.*;
class Prog6{
public static void main(String args[]){
//Take the year
int n=2016;
Year y=Year.of(n);
//test if y is leap or not using isLeap()
boolean flag =y.isLeap(); //flag true if leap