Computer Science, asked by Amido23, 9 months ago

Write a java program for Any 1 Date related program (e.g. Difference between 2 dates)

Answers

Answered by bhavya0898
1

Answer:

Explanation:

Given two dates start_date and end_date with time in the form of strings, the task is to find the difference between two dates in Java.

Examples:

Input: start_date = “10-01-2018 01:10:20”, end_date = “10-06-2020 06:30:50”

Output: 2 years, 152 days, 5 hours, 20 minutes, 30 seconds

Input: start_date = “10-01-2019 01:00:00”, end_date = “10-06-2020 06:00:00”

Output: 1 years, 152 days, 5 hours, 0 minutes, 0 seconds

Method 1: Use SimpleDateFormat and Date class to find the difference between two dates. Below are the steps:

1.Create an object of SimpleDateFormat class and converts string format to date object.

2.Parse both start_date and end_date from a string to produce the date, this can be done by using parse() method of the simpleDateFormat class.

3.Find the time difference between two dates in millisecondes by using the method getTime() in Java as d2.getTime() – d1.getTime().

4.Use date-time mathematical formula to find the difference between two dates. It returns the years, days, hours, minutes, and seconds between the two specifies dates.

5.Print the final result.

Answered by brainliestnp
0

Answer:

hey bro I am attach your answer

thank you for question

Attachments:
Similar questions