显示系统当前时间


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);
}

原文地址:https://www.cnblogs.com/sunda847882651/p/9562733.html