Question

Is it possible to get the TIMEZONE set in JVM using a command in Linux? I am trying to fetch this information from a production box where I wouldn't able to deploy any code to check.

Was it helpful?

Solution

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.

OTHER TIPS

no. this is not possible. you cannot get the time set in JVM using a command in linux. for further information run "java" command in command prompt or console and you will see which commands JVM can receive directly

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top