1、日期格式化

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//可以方便地修改日期格式

String hehe = dateFormat.format(new Date());

System.out.println(hehe);


2、获取独立的年月日,时分秒


Calendar c = Calendar.getInstance();//可以对每个时间域单独修改

int year = c.get(Calendar.YEAR);

int month = c.get(Calendar.MONTH)+1;

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

System.out.println(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second); 


原文链接:https://www.cnblogs.com/Matrix54/archive/2012/05/01/2478158.html

欢迎留言