Urgenthomework logo
UrgentHomeWork
Live chat

Loading..

Java Date and time Homework Help

Java Date and time:

In java the date class is available it is used to capture current date and time. This class supports following constructors.

1. date() – to initialize current date and time

2. date(long millisec) – it accepts number milliseconds since midnight

Example :

{`public class sample
{  ;
 public static void main(String args[])
 {  ;
 Date newdate = new Date();
 // display time and date
 System.out.println(date.toString());
 }  ;
 }  ;
`}

Output:

On June 30 08:45:06

Date comparison;

In java using date class we will compare the date in three ways.

Using getTime() method we can obtain number of milliseconds since midnight

Using before (), after (), and equals () method compare before any particular date or after or two date are equal.

Using compareTo() method we can compare two dates.

Copyright © 2009-2023 UrgentHomework.com, All right reserved.