My system time differs from what java's new Date() tells (+ 4 hours),
so I think it's because some java settings.
How can I make java time to be always as my linux system time?
(by editing some configuration file)
Using Java 7. In Java 7, setting the time-zone is a bit tricky. The Date class (which represents a specific instant in time) doesn't contain any time zone information. First, let's get the current UTC date and a TimeZone object: Date nowUtc = new Date (); TimeZone asiaSingapore = TimeZone.getTimeZone (timeZone);
By default, the JVM reads time zone information from the operating system and stores it in the TimeZone class. To get the default time zone set in the JVM using the method TimeZone.getDefault (). To get the list of all supported timezones, use the method TimeZone.getAvailableIDs (). Java uses the naming convention of the tz database. 2.
Java TimeZone class represents a time zone offset, and also figures out daylight savings. It inherits the Object class. Let's see the declaration of java.util.TimeZone class. It is used to get all the available IDs supported. It is used to get the default TimeZone for this host.
No Time Zone in j.u.Date. As the other correct answers stated, a java.util.Date has no time zone †. It represents UTC/GMT (no time zone offset). Very confusing because its toString method applies the JVM's default time zone when generating a String representation.
You can use TimeZone.setDefault(..)
when your application starts, or pass the timezone as command-line argument: -Duser.timezone=GMT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With