踩坑:java时间格式化yyyy与YYYY的区别
2021/12/28 17:09:35
本文主要是介绍踩坑:java时间格式化yyyy与YYYY的区别,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
查询数据时发现一个bug,前端传了2021-12-28这个日期,转成String类型居然变成了2022-12-28.
经过各种排查,锁定问题可能出现在一个时间转换代码上
DateFormat formatter = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
经过百度发现YYYY代表的含义,和yyyy是不一样的
简单来说,一年有52周,超过52周的,年份+1,2021年有52个周,28号属于第53周,所以会出现年份+1
Java's DateTimeFormatter pattern "YYYY" gives you the week-based-year, (by default, ISO-8601 standard) the year of the Thursday of that week.
The unit that represents week-based-years for the purpose of addition and subtraction.
This allows a number of week-based-years to be added to, or subtracted from, a date. The unit is equal to either 52 or 53 weeks. The estimated duration of a week-based-year is the same as that of a standard ISO year at . 365.2425 Days
The rules for addition add the number of week-based-years to the existing value for the week-based-year field. If the resulting week-based-year only has 52 weeks, then the date will be in week 1 of the following week-based-year.
这篇关于踩坑:java时间格式化yyyy与YYYY的区别的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)
- 2024-05-30【Java】百万数据excel导出功能如何实现
- 2024-05-30我们小公司,哪像华为一样,用得上IPD(集成产品开发)?