您的位置:首页 > 其它

SimpleDateFormat 相关用法

2016-03-29 10:36 323 查看
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:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: