Java Date and time

Java Date and time:
There no need for an importing package for date and time it is there in java.util.
Constructors and Description:

1.Date( ) : initializing the object with current date and time
2.Date(long millisec) : this constructor accepts an argument that converts the data into millisecond.
3.Date(int year, int month, int date) : this constructor show date and time in a sequence of year/month/date manner 4.Date(int year, int month, int date, int hrs, int min) : this constructor show date and time in a sequence of year/month/date/hour/minute manner
5.Date(int year, int month, int date, int hrs, int min, int sec): this constructor show date and time in a sequence of year/month/date/hour/minute/second manner.
6.Date(String s): this constructor used to convert the data into a string.
7.boolean after(Date date): Tests if the current date is after the given date. 8.boolean before(Date date): Tests if the current date is before the given date. 9.int compareTo(Date date) : Compares current date with given date. Returns 0 if the argument Date is equal to the Date; a value less than 0 if the Date is before the Date argument; and a value greater than 0 if the Date is after the Date argument. 10.long getTime() : Returns the number of milliseconds.
11.void setTime(long time): Changes the current date and time to a given time.

1.Just simple example for date and time method

import java.util.*;
import java.time.LocalDate; // import the LocalDate class

public class MyClass
 { 
public static void main(String[] args)
 { 
LocalDate myObj = LocalDate.now(); // Create a date object
System.out.println(myObj); // Display the current date
} 
} 
The output :
2019-06-17 
Translate »