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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:33:40+00:00 2026-05-13T13:33:40+00:00

I have a date stored as a java.sql.Timestamp in a database. The date is

  • 0

I have a date stored as a java.sql.Timestamp in a database. The date is “2010-01-20T19:10:35.000Z” and is equivalent to 1264014635743 ms.

Somehow, the date is formatted differently on the prod machine compared to the dev machine.

The code to format the date is:

private final static String DATE_FORMAT = "yyyy-MM-dd";
public final static SimpleDateFormat APP_DATE_FORMATER = new SimpleDateFormat(DATE_FORMAT);
private static final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone("Etc/UTC");
APP_DATE_FORMATER.setTimeZone(UTC_TIMEZONE);
DateTimeZone.setDefault(DateTimeZone.UTC);

String output = APP_DATE_FORMATER.format(date)

The generated output in dev is the correct “2010-01-20”. But in prod I have “2010-01-21”, one day later!

Of course, since the error occurs on the prod server, I’m limited in my debugging options…

I have double checked, and both server have the same time and timezone. Both clock are synchronized with an ntp server.


[UPDATE] The database in prod has the value: “10-01-20 19:10:35,743000000” for the date field

  • 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-13T13:33:41+00:00Added an answer on May 13, 2026 at 1:33 pm

    My first thought is that this is a concurrency issue. SimpleDateFormat is not thread-safe, yet you’re sharing a static instance. If you need to use java.text formatters in a multi-threaded environment, you should use a ThreadLocal to hold them:

    private static ThreadLocal<DateFormat> _datetimeFormatter = new ThreadLocal<DateFormat>();
    
    private static DateFormat getDatetimeFormatter()
    {
        DateFormat format = _datetimeFormatter.get();
        if (format == null)
        {
            format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            format.setTimeZone(TimeZone.getTimeZone("GMT"));
            _datetimeFormatter.set(format);
        }
        return format;
    }
    
    public static String formatDatetime(Date date)
    {
        return getDatetimeFormatter().format(date);
    }
    

    It’s also possible (but unlikely) that “Etc/UTC” is not found on the server. Do you log the value from getTimeZone()?

    And the third option is, to paraphrase Inigo Montoya, “you are not running the code that you think that you are running.” It could be because your presentation code didn’t properly unload on the server, or there’s another date formatter floating around.

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

Sidebar

Related Questions

I have a Timestamp field in a WebSQL database that is stored like: /Date(1340420400000)/
I have a table in sql where the date format is stored in Hijri.
I have data stored as below in an MS Access database: Date User 20090101
I have a SQL server stored procedure which would accept date as input param
I have stored date (java.util.date object) in a DATETIME field of a Sqlite table.
I have a Date object in Java stored as Java's Date type. I also
I have a date stored in a database in this format: 2011-02-23 13:00:00 I
I have a javascript date stored as a String in java. for example: 1327680000000
I have a core data context with objects that have a date stored in
Possible Duplicate: Format mysql datetime with php Well.. I have stored date(c) in Mysql

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.