Home >Java >javaTutorial >Does `java.sql.Timestamp` Store Time Zone Information?
Is java.sql.Timestamp Timezone Specific?
Background:
JDBC's setTimestamp(int parameterIndex, Timestamp x) method assigns a timestamp to a database column without explicitly specifying the timezone. This raises the question: Does Timestamp carry timezone information?
Answer:
No, java.sql.Timestamp does not inherently carry timezone information.
Explanation:
When calling setTimestamp(...), the JDBC driver relies on the timezone of the virtual machine running the application to determine the date and time to store. This means that the stored value does not retain timezone information.
Example:
Consider the following scenario:
In this case, the driver will convert the UTC time to IST (based on the virtual machine's timezone) and store it as "20121225 12:00:00" in the database.
Storing Timestamps in Specific Timezones:
To store timestamps in a specific timezone, use the setTimestamp(int parameterIndex, Timestamp x, Calendar cal) method. Specify a Calendar object with the desired timezone to ensure that the timestamp is stored accordingly.
Additional Considerations:
The above is the detailed content of Does `java.sql.Timestamp` Store Time Zone Information?. For more information, please follow other related articles on the PHP Chinese website!