当前位置:网站首页>I was stunned by this question that I browsed 746000 times
I was stunned by this question that I browsed 746000 times
2022-07-29 02:26:00 【JavaMonsterr】
I'd like to share with you one interesting thing I found recently , But with a little knowledge .
Let's get you a program to see :
public class MainTest {
public static void main(String[] args) throws Exception {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse("1900-01-01 08:00:00");
System.out.println(simpleDateFormat.format(date));
}
}
You said that the above program logic is a simple time format , What do you say is the output result ?
Just need a glance to know , It must output this result :
1900-01-01 08:00:00
however , You take out the above program , Just run , You will find that the output is like this :
1900-01-01 08:05:43
I was confused at that time .
I know jet lag 8 Hours , Because of the time zone problem .
I know the time difference 1 Hours , It's because of daylight saving time .
But it's bad here 5 branch 43 second , There are zeros and integers , It makes me a little confused .

The above case was shared to me by a reader , Their default time in the database is 1900-01-01, Plus the time zone , It just became 1900-01-01 08:00:00, So when doing data migration through the program, I stepped on this inexplicable time problem .

At the same time, he also sent me a message about this bug Link to :
https://bugs.openjdk.java.net/browse/JDK-8266262

At first glance , This bug It's quite new , It belongs to this year's proposal .
After a closer look, I found that it was the same as before bug repeated :

But here's why :
He said he could look at this link https://www.timeanddate.com/time/zone/china/shanghai?year=1900
Inside this , stay 1900 In the year , A change has taken place :
The timezone offset was UTC +8:05:43 hours all of the period.
Although I didn't quite understand what it meant , But I saw “5 branch 43 second ”:

I understand that it is due to the change of time zone , Caused the time to reset .
Then I followed it , stay stackoverflow I found this on :
https://stackoverflow.com/questions/6841333/why-is-subtracting-these-two-times-in-1927-giving-a-strange-result
I was shocked .
This 10 The question raised years ago has been browsed 746k Time , A very hot question , I didn't even notice :

The specific question is like this :

You just take a glance , I'll translate for you .
Questioner said , He found that 1927-12-31 23:54:07 To 1927-12-31 23:54:08 There's a difference 353 second , It should be 1 Seconds is right ?
But change the time to the following , It's normal again :
String str3 = "1927-12-31 23:54:07";
String str4 = "1927-12-31 23:54:08";
I'll stick the program out and you can run , Look at the result. It's amazing :
public static void main(String[] args) throws ParseException {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str3 = "1927-12-31 23:54:07";
String str4 = "1927-12-31 23:54:08";
Date sDt3 = sf.parse(str3);
Date sDt4 = sf.parse(str4);
long ld3 = sDt3.getTime() /1000;
long ld4 = sDt4.getTime() /1000;
System.out.println(ld4-ld3);
}
But when I ran again , I find : I went to , Well said 353 Seconds? ?
Running out is 1 Seconds? , Nothing wrong :

I even suspect it's jdk Version problem , So I changed jdk 9,11,15 All ran , All are 1 second .
That's strange .
I feel that this question has a problem .

But after I read the best answer below , I just seem to see a clue .
The answer is long , I'll show you all the screenshots first :

The reason is that the author has revised his answer several times .
Why did you change the answer ?
And look back , All the answers are hidden here .
I'll choose the key to tell you .
First look at the first paragraph :

He said (1927 year ) 12 month 31 When day , The time zone in Shanghai has changed .
And about the 1927 Details of Shanghai in , He attached a hyperlink , This hyperlink is the website that appears before , After clicking in, it's like this :

But this one shows :
No further time changes in 1927 in Shanghai
Which translates as :1927 The time of Shanghai did not change further .
This is not the same as what he said below ?
He said below , stay 1927 At midnight at the end of the year , The clock goes back 5 branch 52 second . therefore ,"1927-12-31 23:54:08" It actually happened twice , and Java Take the second time , So there are differences .
In fact, I was stunned to see here , This thing doesn't match , So I went on to search .
Until I found this :
https://coolshell.cn/articles/5075.html/comment-page-2#comments
This is also an article ten years ago .
Here, the author cut a picture of the website at that time :

The screenshot of that year shows :
stay 1927 year 12 month 31 Japan 23:59:59 when , The next second should be 1928 year 1 month 1 Japan 0:0:0, But this time has been adjusted back. 5 branch 52 second , And that's it ,1927 year 12 month 31 Japanese ,23:54:08, therefore , It's done 352 Second crossing .
What does that mean ?
It indicates that the data has been tampered with , Someone tampered with the information on the web page !

What's going on ?
We go back to stackoverflow So let's look down :

This is the first time he has revised his answer , because History changes...
History has changed ...
He said here , If you use TZDB Of 2013a Version of the data , The original problem will no longer show exactly the same behavior .
stay 2013a in , The result will be 358 second , The transition time is 23:54:03, instead of 23:54:08.
He mentioned a TZDB, What is this ?
I don't know either , But I searched .

What he should say is this .
https://www.iana.org/time-zones
Look at the name, you know , It is a time zone database , There should be maintained time zone related data .
in other words , In this time zone database , use 2013a Version of the data , The previous code is another kind of output .
In other words, the data has indeed changed .
The key answer is the next edit :

History has changed again...
History has changed again .
In this time zone database ,2014f In the version , The time for change has moved to 1900-12-31, Now it's just a 343 Second change .
343 second ?
No, it's the one in front of us 5 branch 43 Seconds ?

Okay , Now the jet lag can match ,343 second , But the time is still not right .
Our test time 1900-01-01 08:00:00, The time he wrote here is 1900-12-31.
It's a whole year away ?
good , Let's see what he edited last time :

I personally understand that what he wants to express is like this .
Java To unify standards in time zones , So a one size fits all policy was adopted .
The unified standard is to let UTC In time zone 1900 Any moment before is standard time .
As for the time difference ...
Make it up at the beginning .
therefore ,1900-01-01 00:00:00 add 8 Time difference in hours , yes 1900-01-01 08:00:00, Add in advance on this basis 27 Years from 1927-12-31 That midnight was brought by time callback 343 second .
1900-01-01 08:05:43, I personally think that's how it came about .
And the front stackoverflow The corresponding program inside , We are now executing output 1, But in 10 Years ago , The output is really 353 .
Just like I changed the program to this :

The final output is not 1, It is -342.
Time , It happened. “ Backflow ”.
Okay , It's another useless knowledge point .
Last , Add two more cold knowledge .
The first is that I'm jdk bug The list goes back , The earliest time to ask relevant questions is 2005 year :
https://bugs.openjdk.java.net/browse/JDK-6281408

In this , The official reply is :

This problem will not be fixed , To avoid any compatibility issues .
It means : I know the question , But it's not easy to do ,bug First become feature Well , Let's do it first .
Don't ask , There are historical reasons to ask .
The second cold knowledge is , aforementioned , Time zone in 1927 Year changed .
Do you know why ?
I found this description on a website :
https://zh.wikipedia.org/wiki/%E4%B8%AD%E5%9C%8B%E6%99%82%E5%8D%80

1928 year , The Republic of China 17 year .
That year , The earliest Red Army in the history of the Chinese Communist army , The Fourth Army of the Chinese workers' and peasants' Red Army was established .
That year , Chairman Mao established a rural revolutionary base in Jinggangshan .
That year , sparks of fire , It has become a prairie fire .
边栏推荐
- Vector similarity evaluation method
- PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (2)
- The problem of modifying the coordinate system of point cloud image loaded by ndtmatching function in autoware
- 响应式织梦模板化妆美妆类网站
- Realization of digital tube display based on C51
- Idea connection database
- Excel uses countif statistics
- 年中总结 | 与自己对话,活在当下,每走一步都算数
- 网络安全漏洞管理的探索与实践
- 响应式织梦模板家装建材类网站
猜你喜欢

外包公司“混”了2年,我只认真做了5件事,如今顺利拿到字节 Offer。

The problem of modifying the coordinate system of point cloud image loaded by ndtmatching function in autoware

npm install 报错 Error: EPERM: operation not permitted, rename

响应式织梦模板装修设计类网站

Data security and privacy computing summit - development and application of security intersection in privacy Computing: Learning

裂开了,一次连接池参数导致的雪崩问题

Transform okhttp cache with retrofit

当我看源码的时候,我在想什么?

Jmeter之BeanShell生成MD5加密数据写入数据库

如果时间不够,无法进行充分的测试怎么办?
随机推荐
向量相似度评估方法
Prometheus + AlertManager 消息预警
QT qstackedwidget multi interface switching
“12306”的架构到底有多牛逼?
Kubesphere multi node installation
Virsh console connection failure
[cloud native and 5g] micro services support 5g core network
Feynman learning method (symbol table)
How to quickly design a set of cross end components that support rendering rich text content
Esbuild Bundler HMR
快速掌握Nodejs安装以及入门
防止重复点击
Transform okhttp cache with retrofit
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2, sign in question GJK
Realization of digital tube display based on C51
特殊流&Properties属性集实例遇到的问题及解决方法
ES6事件绑定(v-on用法)
如何利用 RPA 实现自动化获客?
JVM memory overflow online analysis dump file and online analysis open.Hprof file to get JVM operation report how jvisualvm online analysis
关于高并发,我想聊一聊。