Hardware clock
There is only one source of time-keeping within your local computer: the hardware clock built into the box, managed by the host operating system (OS).
The JVM sources the current moment from the host OS, and therefore from the hardware clock. The JVM maintains its own current default time zone through which it interprets/adjusts that moment. But the moment, the point on the timeline, is reported from your hardware clock via the OS, with Java only on the listening end of that conversation.
So, yes, if a user with admin privileges alters the setting of the host computer hardware clock incorrectly, then yes, Java will report an incorrect date-time.
If you Question is, "how do I get the current moment in Java from my local computer without trusting my local computer?", well, that is logically impossible.
If determining the current moment accurately is critical to your app, and you do not trust the clock on the machine hosting your JVM, then you will need an outside source of time.
- Usually that means making a query of a time server over the internet. But you say your JVM does not have access to the Internet.
- One alternative is contacting a time server on your local network. Of course, that means trusting the sysadmin for that time server keeps it properly set. Note that conventional computer clocks are commonly unreliable, drifting a few seconds per month or worse. So a local time server must be kept synchronized with a reliable time source.
- Another alternative is accessing another hardware clock external to the host machine. For example, a radio clock or GPS/Galileo/GLONASS satellite device as discussed here, here, and here.


FYI, the terrible Date
is now legacy, not to be used. Replaced by Instant
. Both represent a moment in UTC (despite the lie told to you by Date::toString
).
Instant instant = Instant.now() ; // Capture the current moment in UTC as determined by your host OS & host hardware.
To see that moment through the wall-clock time used by the people of a particular region, apply a time zone (ZoneId
) to get a ZonedDateTime
object.
ZoneId z = ZoneId.of( "Africa/Tunis" ) ;
ZonedDateTime zdt = instant.atZone( z ) ;