以年月日的格式显示当前时间

以年月日的格式显示当前时间

代码如下:

package Day05;

import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleDatePrintDemo { public static void main(String[] args) {
Date date1 = new Date();
SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr1 = formatter1.format(date1);
System.out.println(date1.toString());
System.out.println(dateStr1);
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String dateStr2 = formatter2.format(date1);
System.out.println(dateStr2);
} }

posted @ 2017-06-20 19:03  辰峰  阅读(387)  评论(0编辑  收藏  举报