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

  • Home
  • SEARCH
  • 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 5960677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:51:34+00:00 2026-05-22T18:51:34+00:00

I have a table which has field with data type as DATETIME. I persist

  • 0

I have a table which has field with data type as DATETIME. I persist a record in this table using java and I calculate current date as as following.

Date date = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();

But When I check my table, it again converts this time into local timezone.

Can some one please explain to me, how to store date in UTC timezone in database.

@Code

I have a db entity ‘Referral’ corresponding to table with date member data type as java.util.Date and using hibernate to save it.

Referral ref = new Referral();
ref.setCreationDate(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime());
referralDAO.save(ref);

Thanks

Jitendra

  • 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-22T18:51:34+00:00Added an answer on May 22, 2026 at 6:51 pm

    MySql DATETIME is stored in a time zone agnostic manner. It just stores year/month/day/hour/minute/second

    How you interpret that information is up to you and your application.
    If you are storing it as UTC, then when you retrieve it you must make sure to interpret it as UTC as well.

    You might be interested in this SO question: How can I get the current date and time in UTC or GMT in Java?

    As mentioned in the answer to that question:

    java.util.Date is always in UTC.
    What makes you think it’s in local
    time? I suspect the problem is that
    you’re displaying it via an instance
    of Calendar which uses the local
    timezone, or possibly using
    Date.toString() which also uses the
    local timezone.

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

Sidebar

Related Questions

I have this table in an Oracle DB which has a primary key defined
I have a SQL table which has a number of fields ID | Value
I have a database structure that has a Person table which contains fields such
I have a table y Which has two columns a and b Entries are:
I have a table User which has an identity column UserID , now what
I have a logging table which has three columns. One column is a unique
I have a table of users which has a username column consisting of a
I have a table called BlogPost which has a 1-to-many relationship with the Comment
I have a T-SQL table variable (not a table) which has an auto incrementing
I have a projects table which has two foreign keys for users (user_id and

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.