2

I'm currently looking for a creative way how to find out if the user.timezone in java was altered by command line arguments or some other custom configuration. So technically I'm looking for a solution how to determine the real timezone of a computer (if this is even possible).

Any help is highly appreciated.

Thanks,

  • 1
    What is the "real TZ" if I embark a plane at LHR with my notebook set to local time and leave the plane at LAX??? – laune Jul 10 '15 at 19:56
  • 1
    by "real TZ" I mean what is setup on your computer. e.g. when your real computer time is set to America/Los_Angeles but running java with -Duser.timezone=UTC I would like to acquire America/Los_Angeles. – snooozer snooozer Jul 10 '15 at 19:58
  • There are various ways to modify the timezone you have after booting. Setting TZ is one way, which you can bypass by running a (Java) subprocess with suitably purified environment (see java.lang.ProcessBuilder). But if a privileged user has hacked (on Linux) `/etc/timezone` you won't be able to see or circumvent that. And neither the original nor the hacked timezone must be the "real" one... – laune Jul 11 '15 at 10:23

2 Answers2

0

Perhaps you could determine it based on their ip and something like GeoLite2. GeoLite2 can get the city and from you could look up that city's timezone (it might even give you the timezone directly, i'm not sure). You can get their ip at ipinfo.

averes
  • 81
  • 2
0

The first solution that pops into my mind is probing external sources. e.g. if you type

wmic timezone get StandardName

in a Windows command line you should get your timezone. Theoretically you could get the output by running this command in Java, as described in this thread.

P.S. It's probably not 'high-quality' to run an obscure command in Java and it's probably not the most efficient thing either. The idea is to somehow use another process that doesn't inherit JVM arguments or other 'customizations' (e.g. command line, Javascript, possibly other script languages, etc.)


Another possibility would be (depending on what client info you have available) to use Google's Time Zone API.

e.g. https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200

Community
  • 1
  • 1
Sandman
  • 2,577
  • 2
  • 21
  • 32