当前位置:网站首页>A tragedy triggered by "yyyy MM DD" and vigilance before New Year's Day~
A tragedy triggered by "yyyy MM DD" and vigilance before New Year's Day~
2022-06-26 06:02:00 【Interview with Java factory】
Preface
When the new year's Day holiday comes , I'm just going out for a few days , However, some App When , I found one that should be caused by the carelessness of the front end bug, stay 2019.12.30 set out , result App It shows 2020.12.30( I was so scared that I thought my order was wrong , Is it time to drag the programmers to heaven ).
In view of the possibility that some programmers may be dragged to heaven , And I used to learn Java I have paid attention to this problem since I was born , So I'd like to put this question to you , I hope we can try our best to avoid carelessness in this regard ( After all, this kind of problem is difficult to detect ).
Text
public class DateTest {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
calendar.set(2019, Calendar.AUGUST, 31);
Date strDate = calendar.getTime();
DateFormat formatUpperCase = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("2019-08-31 to yyyy-MM-dd: " + formatUpperCase.format(strDate));
formatUpperCase = new SimpleDateFormat("YYYY-MM-dd");
System.out.println("2019-08-31 to YYYY/MM/dd: " + formatUpperCase.format(strDate));
}
}
Let's take a look at the results :
2019-08-31 to yyyy-MM-dd: 2019-08-31
2019-08-31 to YYYY/MM/dd: 2019-08-31
If we change the date to 12.31:
2019-12-31 to yyyy-MM-dd: 2019-12-31
2019-12-31 to YYYY-MM-dd: 2020-12-31
The problem arises , Although it is a small detail , But the user will be confused after reading it , But we as developers , Can't be ignorant , Check the document quickly :
y:year-of-era; A serious year , After new year's day ;Y:week-based-year; As long as this week crosses the new year , So this week is the next year ; For example, this year (2019-2020) 12.31 This week is a new year's week , and 12.31 It's Tuesday , That use YYYY It will show 2020, Use yyyy Will follow 1.1 Just started to be 2020.
Although this is a small knowledge point , But many people fell into the pit , You can record it after learning , If you think it's good, you can also like it and pay attention to it . Here, I wish you all a great help in coding , Never bug~
边栏推荐
- Kolla ansible deploy openstack Yoga version
- [intra group questions semester summary] some reference questions for beginners
- Sql查询时间段内容
- 花生壳内网穿透映射NPM私服问题
- kolla-ansible部署openstack yoga版本
- Pre-Sale Analysis
- one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
- Household accounting procedures (First Edition)
- Pytorch (network model training)
- Ribbon load balancing service call
猜你喜欢
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast

MySQL database-01 database overview

423- binary tree (110. balanced binary tree, 257. all paths of binary tree, 100. same tree, 404. sum of left leaves)

Bubble sort

Record how to modify the control across threads

Getting started with Python

怎么把平板作为电脑的第二扩展屏幕

423-二叉树(110. 平衡二叉树、257. 二叉树的所有路径、100. 相同的树、404. 左叶子之和)

Bingc (inheritance)

How to use the tablet as the second extended screen of the PC
随机推荐
MySQL database-01 database overview
通俗易懂的从IDE说起,再谈谈小程序IDE
Selective search for object recognition paper notes [image object segmentation]
重载和重写
Func < T, tresult > Commission - learning record
numpy.tile()
06. talk about the difference and coding between -is and = = again
Day2- syntax basis and variables
C generic speed
numpy.random.choice
机器学习 05:非线性支持向量机
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
Sql语法中循环的使用
Old love letters
Level signal and differential signal
423-二叉树(110. 平衡二叉树、257. 二叉树的所有路径、100. 相同的树、404. 左叶子之和)
Last flight
numpy.frombuffer()
小程序如何关联微信小程序二维码,实现二码聚合
302. 包含全部黑色像素的最小矩形 BFS