Koekiebox
Koekiebox

Reputation: 5973

Get BIOS Time in Java

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 new 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?

Upvotes: 3

Views: 2869

Answers (3)

Peter Lawrey
Peter Lawrey

Reputation: 533930

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.

Upvotes: 0

moritz
moritz

Reputation: 5234

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.

Upvotes: 5

Matthew Gilliard
Matthew Gilliard

Reputation: 9498

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

Upvotes: 7

Related Questions