java 中使用 SimpleDateFormat 时,会遇到 year 和 week year 这两个概念,特此记录。

google 答案:

A week year is in sync with a WEEK_OF_YEAR cycle. All weeks between the first and last weeks (inclusive) have the same week year value. Therefore, the first and last days of a week year may have different calendar yearvalues.

Stackoverflow的一个具体问题及其解释:

For example, January 1, 1998 is a Thursday. If getFirstDayOfWeek() is MONDAY and getMinimalDaysInFirstWeek() is 4 (ISO 8601 standard compatible setting), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. The week year is 1998 for the last three days of calendar year 1997. If, however, getFirstDayOfWeek() is SUNDAY, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997 and their week year is 1997.

查看源码

​java8(jdk1.8.0_171) 中,SimpleDateFormat.java 文件中的 subFormat 函数处理两种 year 的代码:

case PATTERN_WEEK_YEAR: // 'Y'
case PATTERN_YEAR: // 'y'
if (calendar instanceof GregorianCalendar) {
if (count != 2) {
zeroPaddingNumber(value, count, maxIntCount, buffer);
} else {
zeroPaddingNumber(value, 2, 2, buffer);
} // clip 1996 to 96
} else {
if (current == null) {
zeroPaddingNumber(value, style == Calendar.LONG ? 1 : count,
maxIntCount, buffer);
}
}
break;

结论

以上源码说明,year 和 week year 的处理方式一致。至少在java8(jdk1.8.0_171)是这样的。

year 和 weak year 的区别的更多相关文章

  1. retain、strong、weak、assign区别

    1. 假设你用malloc分配了一块内存,并且把它的地址赋值给了指针a,后来你希望指针b也共享这块内存,于是你又把a赋值给(assign)了b.此时a 和b指向同一块内存,请问当a不再需要这块内存,能 ...

  2. ios OC 关键字 copy,strong,weak,assign的区别

    一.先介绍 copy.strong.weak 的区别,如代码所示 @property(copy,nonatomic)NSMutableString*aCopyMStr; @property(stron ...

  3. weak和assign区别

    weak比assign多了一个功能,当对象消失后自动把指针变成nil haofanazenmeban[4002:406590] controller:<SecondViewController: ...

  4. assign, retain, copy, weak, strong

    一.assign, retain, copy 的区别(引用计数 RC reference count) 参考:IOS基础:retain,copy,assign及autorelease 1. 假设你用m ...

  5. iOS开发系列-weak与unsafe_unretained修饰符

    概述 在iOS内存管理中,为防止循环引用,定义类的内部对象属性使用weak.unsafe_unretained修饰符,不产生强引用. 开发中一般使用的weak修饰符,那么接下来说下weak跟unsaf ...

  6. iOS开发系列--无限循环的图片浏览器

    --UIKit之UIScrollView 概述 UIKit框架中有大量的控件供开发者使用,在iOS开发中不仅可以直接使用这些控件还可以在这些控件的基础上进行扩展打造自己的控件.在这个系列中如果每个控件 ...

  7. iOS经典面试题总结--内存管理

    iOS经典面试题总结--内存管理 内存管理 1.什么是ARC? ARC是automatic reference counting自动引用计数,在程序编译时自动加入retain/release.在对象被 ...

  8. JPA,EclipseLink 缓存机制学习(一) 树节点搜索问题引发的思考

    最近在项目在使用JPA+EclipseLink 的方式进行开发,其中EclipseLink使用版本为2.5.1.遇到一些缓存方面使用不当造成的问题,从本篇开始逐步学习EclipseLink的缓存机制. ...

  9. 李洪强iOS经典面试题135-Objective-C

    可能碰到的iOS笔试面试题(5)--Objective-C 面试笔试都是必考语法知识的.请认真复习和深入研究OC. Objective-C 方法和选择器有何不同?(Difference between ...

随机推荐

  1. apicloud实现各种自定义弹层组件

  2. C盘突然爆满

    C盘突然爆满!幸好还开的机!~~ 因为是突然就爆满了,想着应该是虚拟内存的原因!于是就开始了探索.... 1.文件夹选项中把所有文件都显示出来. 2.在C盘你就会看到一个“pagefile.sys”的 ...

  3. CABaRet: Leveraging Recommendation Systems for Mobile Edge Caching

    CABaRet:利用推荐系统进行移动边缘缓存 本文为SIGCOMM 2018 Workshop (Mobile Edge Communications, MECOMM)论文. 笔者翻译了该论文.由于时 ...

  4. css清除浮动的3种方式

    前言: 当不给父元素设置宽高时,父元素的宽高会被子元素的内容撑开.但当子元素设置浮动属性(float) 后, 子元素会溢出到父元素外,父元素的宽高也不会被撑开,这称之为“高度塌陷”.可以理解为使用浮动 ...

  5. Kali学习笔记44:SQLMAP

    SQLMAP漏洞检测技术: 1.基于布尔的盲注检测:' and 1=1   'and 1=2等 2.基于时间的盲注检测:' and (select * from (select(sleep(20))) ...

  6. [Swift]LeetCode35. 搜索插入位置 | Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  7. [Swift]LeetCode70. 爬楼梯 | Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  8. PHP文件域上传

    PHP中使用文件域上传文件,需要几个步骤,首先先判断有无文件域,然后判断是否选择了文件,最后判断文件是否上传成功. 需要注意的是 表单中有文件域,必须将method设置为post, enctype设置 ...

  9. Redis 设计与实现 (九)--Lua

    EVAL script numkeys key [key ...] arg [arg ...] script:     你的lua脚本 numkeys:  key的个数 key:           ...

  10. B+树的Copy-on-Write设计

    本文主要介绍B+树的Copy-On-Write,包括由来.设计思路和核心源码实现(以Xapian源码为例).中文的互联网世界里,对B树.B+树的科普介绍很丰富,但对它们在工业界的实际使用却几乎没有相关 ...