0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Java】日付から差分を算出したい

Last updated at Posted at 2020-03-24

開始日付、終了日付をもとに処理時間を算出したかった。

date.java
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;

		// Date型に変換
		try {
			start = sdf.parse("2020/03/23 12:30:12");
			end = sdf.parse("2020/03/23 12:31:12");
		} catch (java.text.ParseException e) {
			e.printStackTrace();
		}

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

		// ミリ秒
		System.out.println(processTime);
	}
}

実行結果:

60000
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?