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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:38:03+00:00 2026-05-30T15:38:03+00:00

I have variable that store data datetime UTC from database. I want to make

  • 0

I have variable that store data datetime UTC from database. I want to make it in Local datetime format, can i do that?

for example:

Date dateFromDB = getfromDB();

dateFromDB = UTCtoLocalTimezone(dateFromDB);

What the code in method UTCtoLocalTimezone?

Or do you have any better solution?
thankyou!

  • 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-30T15:38:04+00:00Added an answer on May 30, 2026 at 3:38 pm

    Personally I would use Joda Time:

    DateTimeZone zone = ...;
    DateTime dateTime = new DateTime(date.getTime(), zone);
    

    Joda Time is a much better date and time API than the built-in one, but that would work too:

    TimeZone zone = ...;
    Calendar calendar = Calendar.getInstance(zone);
    calendar.setTime(date);
    

    I wouldn’t use the (deprecated) Date constructor though. For one thing, it doesn’t do what you appear to think it does… this:

     new Date(2012,03,02,11,30,0);
    

    constructs a value representing the 2nd of February in the year 3912…

    This won’t be a problem if you’re fetching the Date from the database, but obviously it will affect unit testing. You should really avoid all the deprecated members of Date – they’re deprecated for good reason.

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

Sidebar

Related Questions

I have a php page that pulls data from a mysql database based on
I have global variable fan_coil_ai_bi, and I use that variable to store some data
I have a variable called $tags , which just references from a database field.
I have a heirarchy of classes that get initialized from a database. I am
I have a big fat query that's written dynamically to integrate some data. Basically
I need to store data that looks like this: <root> <child-one> value 1 value
basically i want to hold a parameter that retrieve value from $.post() call like
I am using Numpy to store data into matrices. Coming from R background, there
I have a page with a button that when I click, it retrieves data
I have a task to store large amount of gps data and some extra

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.