How to compare dates in java algorithm with source code

5-**c)** Write a java program to read the time intervals (HH:MM) and to compare system time if the system time between your time intervals print correct time and exit else try again to repute the same thing. By using String Tokenizer class.

**Description:**

Intially take the input interval of time in hours, minutes and seconds. The system time can be read as using the object of the class GregorianCalendar . This GregorianCalendar class contains a method by name get which returns a required value from the hour, minutes and seconds of the system time.

Calendar class contains variables hour, minute,second which gives the system time through the object of the class GregorianCalendar.

**Source code :**

import java.io.*;

import java.util.*;

import java.text.*;

public class Time

{

public static void main(String ar[])

{

int HOUR,SECOND,MINUTE;

Scanner s=new Scanner(System.in);

System.out.println(“Enter seconds : “);

int a=s.nextInt();

System.out.println(“Enter Minutes : “);

int b=s.nextInt();

System.out.println(“Enter Hours : “);

int c=s.nextInt();

GregorianCalendar date=new GregorianCalendar();

int second=date.get(Calendar.SECOND);

int minute=date.get(Calendar.MINUTE);

int hour=date.get(Calendar.HOUR);

if(second >a)

SECOND=second-a;

else

SECOND=a-second;

if(minute >b)

MINUTE=minute-b;

else

MINUTE=b-minute;

if(hour>c)

HOUR=hour-c;

else

HOUR=c-hour;

System.out.println(“Difference between two times is “+HOUR+”:”+MINUTE+”:”+SECOND);

} }

**Expected Output :**

Enter seconds : 02

Enter Minutes :10

Enter Hour :8

Difference between two times is

1 :13 :40

- How to compare dates in java|algorithm with source code
- Java roll dice 10000 times with algorithm and source code
- Write a Java program that displays the number of characters, lines and words in a text
- Write a Java program that reads a file and displays the file on the screen with a line number before each line
- Write a Java program that reads a file name from the user, then displays information about whether the file exists, readable, writable, type of file and the length of the file in bytes
- Java program to make frequency count of vowels, consonants, special symbols, digits, words in a given text
- Write a Java program for sorting a given list of names in ascending order
- Write a java program to Checks whether a given string is a palindrome or not
- Write a java program to perform multiplication of two matrices
- write a java program that print the fibonacci series for a give number.
- Write a Java Program that find the factorial of a number
- Write a Java program that find prime numbers between 1 to n
- Write a Java program that prints all real and imaginary solutions to the quadratic equation
- Odd and Even number in java | Algorithm
- Even number in java | algorithm with source code
- find unique elements in array java | algorithm and source code
- Write a Java program for sorting a given list of names in ascending order
- write a java program that print the fibonacci series for a give number.
- Write a Java program that prints all real and imaginary solutions to the quadratic equation
- Missing Number in java with example
- Java greater number using loop
- Java Print function with example | Difference between print () and println () in java
- What is the Fibonacci series? in java | Displaying the Fibonacci sequence using a loop
- Odd and Even number in java | Algorithm
- Even number in java | algorithm with source code
- Java Area of Rectangle
- What is a polygon? | Area of Triangle in java
- To calculate Area of Circle in java program
- Java Addition through user input
- Addition program in java with source code

How to compare dates in java algorithm with source code

https://en.wikipedia.org/wiki/Java_(programming_language)