Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 719361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:37:59+00:00 2026-05-14T05:37:59+00:00

I need to force any time related operations to GMT/UTC, regardless the timezone set

  • 0

I need to force any time related operations to GMT/UTC, regardless the timezone set on the machine. Any convenient way to so in code?

To clarify, I’m using the DB server time for all operations, but it comes out formatted according to local timezone.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:37:59+00:00Added an answer on May 14, 2026 at 5:37 am

    The OP answered this question to change the default timezone for a single instance of a running JVM, set the user.timezone system property:

    java -Duser.timezone=GMT ... <main-class>
    

    If you need to set specific time zones when retrieving Date/Time/Timestamp objects from a database ResultSet, use the second form of the getXXX methods that takes a Calendar object:

    Calendar tzCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    ResultSet rs = ...;
    while (rs.next()) {
        Date dateValue = rs.getDate("DateColumn", tzCal);
        // Other fields and calculations
    }
    

    Or, setting the date in a PreparedStatement:

    Calendar tzCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    PreparedStatement ps = conn.createPreparedStatement("update ...");
    ps.setDate("DateColumn", dateValue, tzCal);
    // Other assignments
    ps.executeUpdate();
    

    These will ensure that the value stored in the database is consistent when the database column does not keep timezone information.

    The java.util.Date and java.sql.Date classes store the actual time (milliseconds) in UTC. To format these on output to another timezone, use SimpleDateFormat. You can also associate a timezone with the value using a Calendar object:

    TimeZone tz = TimeZone.getTimeZone("<local-time-zone>");
    //...
    Date dateValue = rs.getDate("DateColumn");
    Calendar calValue = Calendar.getInstance(tz);
    calValue.setTime(dateValue);
    

    Usefull Reference

    https://docs.oracle.com/javase/9/troubleshoot/time-zone-settings-jre.htm#JSTGD377

    https://confluence.atlassian.com/kb/setting-the-timezone-for-the-java-environment-841187402.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a way to force calling a constant version of member function. I'm
In IronPython is there any way to force the expression containing integer values to
I am having trouble finding a way to force any display resolution/timing I want
Is there any way (server or client side) to force the browser to pull
Is there any way to force a listview control to treat all clicks as
I need to force quit my app when I pressed the Answer button in
I need to force page break after each record from datasource. I tried <break
There is a moment in my app, that I need to force to show
I'm trying to make a force directed graph using d3.layout.force , and I need
There's autocomplete , but it doesn't force the selection of an item. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.