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:

posted @ 2016-03-29 10:36  权杖攻城狮  阅读(231)  评论(0编辑  收藏  举报