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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:08:15+00:00 2026-06-06T20:08:15+00:00

When running some tests I came across the following issue. When using: private String

  • 0

When running some tests I came across the following issue. When using:

private String printStandardDate(Date date) {
    return DateFormat.getDateTimeInstance(
        DateFormat.SHORT, DateFormat.SHORT).format(date);
}

I found this produced different formats of Date depending on the location the tests where run from. So locally in windows / eclipse I got a result: 04/02/12 18:18 but on the Linux box in America I get 2/4/12 6:18 PM

This causes my Tests/Build to fail:

expected:<[04/02/12 18:18]> but was:<[2/4/12 6:18 PM]>

Could anyone explain this behavior?

  • 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-06-06T20:08:17+00:00Added an answer on June 6, 2026 at 8:08 pm

    That’s not strange, that’s exactly how it’s supposed to work.

    The API documentation of DateFormat.getDateTimeInstance says:

    Gets the date/time formatter with the given date and time formatting styles for the default locale.

    The default locale is different on your Windows system than on the Linux box in America.

    If you want exact control over the date and time format, use SimpleDateFormat and specify the format yourself. For example:

    private String printStandardDate(Date date) {
        return new SimpleDateFormat("dd/MM/yy HH:mm").format(date);
    }
    

    Even better would be to re-use the SimpleDateFormat object, but beware that it is not thread-safe (if the method might be called from multiple threads at the same time, things will get messed up if those threads use the same SimpleDateFormat object).

    private static final DateFormat DATE_FORMAT =
        new SimpleDateFormat("dd/MM/yy HH:mm");
    
    private String printStandardDate(Date date) {
        return DATE_FORMAT.format(date);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using TPTP to profile some slow running Java code an I came across
The problem I'm using fitnesse for running some automated tests. There is a class
We have some unit tests running against a SQL server 2000 database using the
While developing my application i came across some comparison stuff here was it: string
I am running some tests for extjs library that we are using in our
I am running through some tests about using ArrayLists and List. Speed is very
I remember running some tests a some months ago with gettext and the following
I was trying to get some tests running inside a console application using System;
I'm running some tests comparing the sha1 algorithm implemented in javascript - got from
I am running some tests with linq, how can I check what queries SQL

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.