美文网首页
DateFormat类和SimpleDateFormat类

DateFormat类和SimpleDateFormat类

作者: kanaSki | 来源:发表于2019-06-17 21:38 被阅读0次

DateFormat是抽象类

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 将日期按指定格式转为字符串
        String format = df.format(new Date());
        System.out.println(format);
        // 将日期字符串将时间转为指定日期对象
        Date dateNew = df.parse(format);
        System.out.println(dateNew);

[日期格式化参数对照表](https://www.cnblogs.com/WEB-PHP/p/9209565.html

        // 年中的天数
        SimpleDateFormat df3 =new SimpleDateFormat("D");
        String format1 = df3.format(new Date());
        System.out.println(format1);

相关文章

网友评论

      本文标题:DateFormat类和SimpleDateFormat类

      本文链接:https://www.haomeiwen.com/subject/khxtqctx.html