[Java] I want to calculate the difference from the date

I wanted to calculate the processing time based on the start date and end date.


import java.text.SimpleDateFormat;
import java.util.Date;

public class date {

	public static void main(String[] args) {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Date start = null;
		Date end = null;

		//Convert to Date type
		try {
			start = sdf.parse("2020/03/23 12:30:12");
			end = sdf.parse("2020/03/23 12:31:12");
		} catch (java.text.ParseException e) {

		long timeStart = start.getTime();
		long timeEnd = end.getTime();
		long processTime = timeEnd - timeStart;


Execution result:


Recommended Posts

[Java] I want to calculate the difference from the date
Run R from Java I want to run rJava
I want to write quickly from java to sqlite
The road from JavaScript to Java
[JDBC] I tried to access the SQLite3 database from Java.
[Android, Java] Convenient method to calculate the difference in days
I want to use the Java 8 DateTime API slowly (now)
I want to simplify the conditional if-else statement in Java
In Java, I want to trim multiple specified characters from only the beginning and end.
I want to return to the previous screen with kotlin and java!
If you want to change the Java development environment from Eclipse
[Android, Java] Method to find the elapsed date from two dates
[Java] How to set the Date time to 00:00:00
How to get the date in java
I want to stop Java updates altogether
[Java] I want to perform distinct with the key in the object
I want to return a type different from the input element with Java8 StreamAPI reduce ()
I went to the Java Women's Club # 1
[Android] I want to get the listener from the button in ListView
I want to judge the necessity of testing by comparing the difference of class files when refactoring Java
I want to get the IP address when connecting to Wi-Fi in Java
I want to get the field name of the [Java] field. (Old tale tone)
I translated the grammar of R and Java [Updated from time to time]
I want to find out what character the character string appears from the left
I want to output the day of the week
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I want to send an email in Java.
I want to graduate from npm install properly [2020]
I want to use java8 forEach with index
I want to var_dump the contents of the intent
rsync4j --I want to touch rsync in Java.
I want to play with Firestore from Rails
I want to truncate after the decimal point
I want to get the value in Ruby
Changes from Java 8 to Java 11
Sum from Java_1 to 100
From Java to Ruby !!
[Promotion of Ruby comprehension (1)] When switching from Java to Ruby, first understand the difference.
I want to play a GIF image on the Andorid app (Java, Kotlin)
I want you to use Scala as Better Java for the time being
I want to get only the time from Time type data ...! [Strftime] * Additional notes
[Java] Calculate the day of the week from the date (Calendar class is not used)
I want to do something like "cls" in Java
I want to embed any TraceId in the log
Tokoro I rewrote in the migration from Wicket 7 to 8
How to write Scala from the perspective of Java
[Java] How to extract the file name from the path
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
# 2 [Note] I tried to calculate multiplication tables in Java.
I want to judge the range using the monthly degree
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
I want to dark mode with the SWT app
6 features I missed after returning to Java from Scala
I want to transition screens with kotlin and java!
I want to call the main method using reflection
[Rough commentary] I want to marry the pluck method
I tried to implement the Euclidean algorithm in Java
I want to get along with Map [Java beginner]
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!