
正文
SimpleDateFormat 相关用法
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
parse(String s)返回的是一个Date类型数据,format(Date d)返回的是一个String类型的数据
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
//SimpleDateFormat中的format方法可以 //把Date型的字符串转换成特定格式的String类型
String oldDateStr = sd.format(new Date());System.out.println(oldDateStr); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//SimpleDateFormat中的parse方法可以 //把String型的字符串转换成特定格式的date类型
Date newDate=format.parse(oldDateStr+" 23:59:59"); System.out.println(newDate);SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); String newDateStr=sdf.format(newDate); System.out.println(newDateStr);
output:








