java.text.SimpleDateFormat()を実装するサンプル

1.TimeStampUtil.java
クラスの定義
package study;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

public class TimeStampUtil {
public static String formatTimeStamp(Timestamp timestamp, String timeFormat) {
return new SimpleDateFormat(timeFormat).format(timestamp);
}

public static Timestamp current() {
return new Timestamp(System.currentTimeMillis());
}

}

2.mainクラス
package study;
public class TimeStampDemo {

public static final String TIME_VALUE_FORMAT = “yyyy/MM/dd HH:mm:ss”;

public static void main(String[] args) {
String aa = TimeStampUtil.formatTimeStamp(TimeStampUtil.current(), TIME_VALUE_FORMAT);
System.out.println(“現在時間:\n” + aa);

}

}

現在時間:
2018/07/17 12:02:52

Comments are closed.