zoukankan      html  css  js  c++  java
  • Java时间格式化遇到的坑

    Java时间格式化时YYYY(大写)和yyyy(小写)的有区别,其中y 是Year、Y 表示的是Week year;Week year意思是当天所在的周属于的年份,一周从周日开始,周六结束,只要本周跨年,那么这周就算入下一年。2017-12-31是周日,刚好是2017最后一周并跨年,就取到2018年了;

    public static void main(String[] args) throws ParseException {
    SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
    Date currentDate=df.parse("2017-12-31");
    System.out.println("yyyy-MM-dd:"+DateFormatUtils.format(currentDate,"yyyy-MM-dd"));
    System.out.println("YYYY-MM-dd:"+DateFormatUtils.format(currentDate,"YYYY-MM-dd"));
    }

    测试结果:
    yyyy-MM-dd:2017-12-31
    YYYY-MM-dd:2018-12-31

    转载:https://www.cnblogs.com/water-xu/p/12068401.html

  • 相关阅读:
    HDU 4801 Pocket Cube
    HDU 5008 Boring String Problem(后缀数组+二分)
    2-Sat问题
    后缀数组
    树形DP
    图论
    SRM 628 DIV2
    组合博弈
    Github使用笔记
    VS2010+OpenCV配置
  • 原文地址:https://www.cnblogs.com/haoyuekey/p/12118390.html
Copyright © 2011-2022 走看看