开发者

Get BIOS Time in Java

开发者 https://www.devze.com 2023-02-24 06:47 出处:网络
Is there a way in Java to get the BIOS date and time? Does Java use the BIOS (Basic Input/Output System) Datetime when you call java.util.Calendar.getInstance() or ne开发者_运维技巧w java.util.Date()

Is there a way in Java to get the BIOS date and time?

Does Java use the BIOS (Basic Input/Output System) Datetime when you call java.util.Calendar.getInstance() or ne开发者_运维技巧w java.util.Date()?

I do know that Java somehow works the current Date and time using January 1, 1970, 00:00:00 GMT as a base.

But how exactly?


It asks the operating system, which may or may not ask the BIOS.

These dates are based on that epoch in this way:

new Date(0); // == Thu Jan 01 01:00:00 GMT 1970


There are ways, but these are not portable. One way is to call hwclock from your java program via Runtime.exec() and parse the output of hwclock (Linux). Other ways would be using the JNI and do a system call.


Both of these use System.currentTimeMillis() which obtains the GMT time from the OS. The OS may in turn get the time from the BIOS but that is up to the OS.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号