当前位置:网站首页>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~
边栏推荐
猜你喜欢

Household accounting procedures (First Edition)
从新东方直播来探究下小程序音视频通话及互动直播

On site commissioning - final method of kb4474419 for win7 x64 installation and vs2017 flash back

Kolla ansible deploy openstack Yoga version

Kolla ansible deploy openstack Yoga version

pytorch(网络模型训练)

重载和重写

Redis底层数据结构

小程序第三方微信授权登录的实现

pytorch(环境、tensorboard、transforms、torchvision、dataloader)
随机推荐
numpy.log
Sql语法中循环的使用
Level signal and differential signal
pytorch(网络模型训练)
【 langage c】 stockage des données d'analyse approfondie en mémoire
Pytorch (network model)
Ribbon load balancing service call
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast
Implement the runnable interface
Day4 branch and loop
[intra group questions semester summary] some reference questions for beginners
cross entropy loss = log softmax + nll loss
Force buckle 875 Coco, who likes bananas
Younger sister Juan takes you to learn JDBC -- two days' Sprint Day2
canal部署、原理和使用介绍
The purpose of writing programs is to solve problems
421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)
从新东方直播来探究下小程序音视频通话及互动直播
适配器模式
数据可视化实战:实验报告