2
2

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 日付を扱うDate d = new Date();

2
Last updated at Posted at 2015-11-10

■currentTimeMillis()
■Main23.java

public class Main23 {
	public static void main(String[] args) {
long start = System.currentTimeMillis();

		long end = System.currentTimeMillis();
		System.out.println("処理にかかった時間は・・・"
				+ (end -start) + "ミリ秒でした" );

	}
}

■実行結果
処理にかかった時間は・・・0ミリ秒でした


■現在日時を持つDateインスタンスの生成
Date d = new Date();
■簡単現在日時表示

		Date now2 = new Date();
		System.out.println("現在日時は" + now2 + "です。");

■指定時点の日時を持つDateインスタンスの生成
Date d = new Date(long 値);
long値の日時を持つインスタンス生成

■Date(long 値)
引数に1970年1月1日午前0時からの経過時間をミリ秒で指定し、指定したミリ秒が表す日時を保持したDateオブジェクトを生成します。


import java.util.Date;

public class Test02 {
	public static void main(String[] args) {
		Date past = new Date(1447205637038L);
		System.out.println(past);
	}
}

実行結果
Wed Nov 11 10:33:57 JST 2015

■Main23.java

import java.util.Date;
public class Main23 {
	public static void main(String[] args) {

		Date now = new Date();
                System.out.println(now);
		System.out.println(now.getTime());
		Date past1 = new Date(1316622225935L);
		System.out.println(past1);

	}
}

■実行結果
Tue Nov 10 18:32:38 JST 2015
1447147958455
Thu Sep 22 01:23:45 JST 2011

■実行結果
現在日時はTue Nov 10 19:11:29 JST 2015です。

2
2
1

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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?