JVM makes some statistics about the app available via JMX, and some are available by default, so it's rather likely you will be able to retrieve them from your app, too. You can use jconsole
tool to connect to a Java app and read those values. I don't see the clock time being one of them, but you can check the application's startup time, and the uptime. Adding one to the other gives you the current time as the app sees it. You can find both values in jconsole
in the "MBeans" tab: in the tree on the left select: java.lang / Runtime / Attributes - they will be called "Uptime" and "StartTime". Uptime is in milliseconds and StartTime is in milliseconds since January 1st, 1970.
PS: If the above doesn't work, you can try to retrieve the time indirectly. The time returned by System.currentTimeMillis()
is based on the machine's clock, so it should be the same as returned by any other program that queries the clock, e.g. the command-line date
command. One possible deviation would be the possibility of the java application using a different time zone, e.g. due to environment variables set differently than for your command-line program.