「Java」Timestampクラスのサンプル

2022年4月5日

環境
JDK1.8
Eclipse2019-12
書式
1.public long getTime()
このTimestampオブジェクトで表される、1970年1月1日00:00:00 GMTからのミリ秒数を返します。
2.public final Class<?> getClass()
このObjectの実行時クラスを返します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.Test;
import java.sql.Timestamp;
public class TimeStampDemo {
public static void main(String[] args) {
// Timestampオブジェクト生成
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
System.out.println("実行時の時刻: " + timestamp);
System.out.println("実行時の時刻(ミリ秒数): " + timestamp.getTime());
System.out.println("実行時クラス名: " + timestamp.getClass());
}
}
package com.arkgame.Test; import java.sql.Timestamp; public class TimeStampDemo { public static void main(String[] args) { // Timestampオブジェクト生成 Timestamp timestamp = new Timestamp(System.currentTimeMillis()); System.out.println("実行時の時刻: " + timestamp); System.out.println("実行時の時刻(ミリ秒数): " + timestamp.getTime()); System.out.println("実行時クラス名: " + timestamp.getClass()); } }
package com.arkgame.Test;

import java.sql.Timestamp;

public class TimeStampDemo {

      public static void main(String[] args) {
            // Timestampオブジェクト生成
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            System.out.println("実行時の時刻: " + timestamp);
            System.out.println("実行時の時刻(ミリ秒数): " + timestamp.getTime());
            System.out.println("実行時クラス名: " + timestamp.getClass());
      }

}

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
実行時の時刻: 2022-04-05 14:45:30.73
実行時の時刻(ミリ秒数): 1649137530730
実行時クラス名: class java.sql.Timestamp
実行時の時刻: 2022-04-05 14:45:30.73 実行時の時刻(ミリ秒数): 1649137530730 実行時クラス名: class java.sql.Timestamp
実行時の時刻: 2022-04-05 14:45:30.73
実行時の時刻(ミリ秒数): 1649137530730
実行時クラス名: class java.sql.Timestamp

 

Java

Posted by arkgame