在java中 怎么把获取的系统时间转化成数字

2025-06-20 12:04:08
推荐回答(2个)
回答1:

long time=new Date().getTime();
System.out.println(""+time);

Date date=new Date(time);
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(sdf.format(date));

回答2:

public class Test19 {
public static void main(String[] args) {
// assert args.length==1;
int year, month, date, hour, minute, second;
Calendar now = Calendar.getInstance();
now = Calendar.getInstance();
year = now.get(Calendar.YEAR);
month = now.get(Calendar.MONTH);
date = now.get(Calendar.DATE);
hour = now.get(Calendar.HOUR_OF_DAY);
minute = now.get(Calendar.MINUTE);
second = now.get(Calendar.SECOND);
}
}