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 83347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:45:33+00:00 2026-05-10T21:45:33+00:00

I used a new Date() object to fill a field in a MySQL DB,

  • 0

I used a new Date() object to fill a field in a MySQL DB, but the actual value stored in that field is in my local timezone.

How can I configure MySQL to store it in the UTC/GMT timezone?

I think, configuring the connection string will help but I don’t know how. There are many properties in the connection string like useTimezone, serverTimzone, useGmtMillisForDatetimes, useLegacyDatetimeCode, …

  • 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. 2026-05-10T21:45:34+00:00Added an answer on May 10, 2026 at 9:45 pm

    The short answer is:

    • add ‘default-time-zone=utc’ to my.cnf
    • in your code, always ‘think’ in UTC, except when displaying dates for your users
    • when getting/setting dates or timestamps with JDBC, always use the Calendar parameter, set to UTC:

      resultset.getTimestamp(‘my_date’, Calendar.getInstance(TimeZone.getTimeZone(‘UTC’)));

    • either synchronize your servers with NTP, or rely only on the database server to tell you what time it is.

    The long answer is this:

    When dealing with dates and timezones in any database and with any client code, I usually recommend the following policy:

    1. Configure your database to use UTC timezone, instead of using the server’s local timezone (unless it is UTC of course).

      • How to do so depends on your database server. Instructions for MySQL can be found here: http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html. Basically you need to write this in my.cnf: default-time-zone=utc

      • This way you can host your database servers anywhere, change your hosting location easily, and more generally manipulate dates on your servers without any ambiguity.

      • If you really prefer to use a local timezone, I recommend at least turning off Daylight Saving Time, because having ambiguous dates in your database can be a real nightmare.
        • For example, if you are building a telephony service and you are using Daylight Saving Time on your database server then you are asking for trouble: there will be no way to tell whether a customer who called from ‘2008-10-26 02:30:00’ to ‘2008-10-26 02:35:00’ actually called for 5 minutes or for 1 hour and 5 minutes (supposing Daylight Saving occurred on Oct. 26th at 3am)!
    2. Inside your application code, always use UTC dates, except when displaying dates to your users.

      • In Java, when reading from the database, always use:

      Timestamp myDate = resultSet.getTimestamp(‘my_date’, Calendar.getInstance(TimeZone.getTimeZone(‘UTC’)));

      • If you do not do this, the timestamp will be assumed to be in your local TimeZone, instead of UTC.
    3. Synchronize your servers or only rely on the database server’s time

      • If you have your Web server on one server (or more) and your database server on some other server, then I strongly recommend you synchronize their clocks with NTP.

      • OR, only rely on one server to tell you what time it is. Usually, the database server is the best one to ask for time. In other words, avoid code such as this:

      preparedStatement = connection.prepareStatement(‘UPDATE my_table SET my_time = ? WHERE […]’);
      java.util.Date now = new java.util.Date(); // local time! 🙁
      preparedStatement.setTimestamp(1, new Timestamp(now.getTime()));
      int result = preparedStatement.execute();

      • Instead, rely on the database server’s time:

      preparedStatement = connection.prepareStatement(‘UPDATE my_table SET my_time = NOW() WHERE […]’);
      int result = preparedStatement.execute();

    Hope this helps! 🙂

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

Sidebar

Related Questions

What are some of the new features that can be used in .NET 2.0
Is a new (or different) instance of TestCase object is used to run each
As I understand (Perl is new to me) Perl can be used to script
Where a new system concept or new technology is used, one has to build
Hi I am new and I am used to MS SQL Manager's Attach/Detatch functionality
Has anyone here ever used C++'s placement new? If so, what for? It looks
My most used mini pattern is: VideoLookup = new ArrayList { new ArrayList {
I've never used SOAP before and I'm sort of new to Python. I'm doing
I used to work with VWD and now I try to install the new
I know it can be done but am having issues getting it to work.

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.