显示系统当前时间


public static void main(String[] args) {
show();//方法1
System.out.println("-------------");
showtime();//方法2
}
public static void show() {
Date date = new Date();//获取当前时间(类型是date)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//时间的格式化,注意格式的大小写
String newdate = sdf.format(date);
System.out.println(newdate);
}
public static void showtime() {
long time=System.currentTimeMillis();//获取系统当前时间(类型是long)
SimpleDateFormat sd=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");//时间的格式化
Date d = new Date(time);
String s = sd.format(d);
System.out.println(s);
}

posted @ 2018-08-30 21:10  Captain灬  阅读(252)  评论(0编辑  收藏  举报