实例操作-取得完整日期

设计一个取得日期的类,此类可以取得系统的当前时间和时间戳。

package book;
import java.util.Date;
import java.text.SimpleDateFormat;
class DateTime{
	private SimpleDateFormat sdf = null;
	public String getDate() {
		this.sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		return this.sdf.format(new Date());
	}
	public String getDateComplete() {
		this.sdf = new SimpleDateFormat("yyy年MM月dd日 HH时mm分ss秒SSS毫秒");
		return this.sdf.format(new Date());
	}
	public String getTimeStamp() {
		this.sdf = new SimpleDateFormat("yyyMMddHHmmssSSS");
		return this.sdf.format(new Date());
	}
}
public class JiOu{
	public static void main(String args[]) throws Exception{
		DateTime dt = new DateTime();
		System.out.println("系统日期:"+dt.getDate());
		System.out.println("中文日期:"+dt.getDateComplete());
		System.out.println("时间戳:"+dt.getTimeStamp());
	}
}

运行结果:

系统日期:2018-08-04 16:40:19.394
中文日期:2018年08月04日 16时40分19秒394毫秒
时间戳:20180804164019394

猜你喜欢

转载自blog.csdn.net/Javaxiaobaismc/article/details/81412593