版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31083947/article/details/78947925
/**
* 可以格式化的时间
* @return
*/
private static String getTime1(){
Date nowTime = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String currTime = dateFormat.format( nowTime );
return currTime ;
}
/**
* 可以得到各部分的值
* @return
*/
private static String getTime2(){
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR); //年
int month = c.get(Calendar.MONTH); //月
int date = c.get(Calendar.DATE); //日
int hour = c.get(Calendar.HOUR_OF_DAY);//时
int minute = c.get(Calendar.MINUTE); //分
int second = c.get(Calendar.SECOND); //秒
return year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second;
}