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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:40:53+00:00 2026-05-26T05:40:53+00:00

I need to build a date format like dd/MM/yyyy . It’s almost like DateFormat.SHORT

  • 0

I need to build a date format like dd/MM/yyyy. It’s almost like DateFormat.SHORT, but contains 4 year digits.

I try to implement it with

new SimpleDateFormat("dd//MM/yyyy", locale).format(date);

However for US locale the format is wrong.

Is there a common way to format date that changes pattern based on locale?

Thank you

  • 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-26T05:40:54+00:00Added an answer on May 26, 2026 at 5:40 am

    I would do it like this:

        StringBuffer buffer = new StringBuffer();
    
        Calendar date = Calendar.getInstance();
        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
        FieldPosition yearPosition = new FieldPosition(DateFormat.YEAR_FIELD);
    
        StringBuffer format = dateFormat.format(date.getTime(), buffer, yearPosition);
        format.replace(yearPosition.getBeginIndex(), yearPosition.getEndIndex(), String.valueOf(date.get(Calendar.YEAR)));
    
        System.out.println(format);
    

    Using a FieldPosition you don’t really have to care about wheter the format of the date includes the year as “yy” or “yyyy”, where the year ends up or even which kind of separators are used.

    You just use the begin and end index of the year field and always replace it with the 4 digit year value and that’s it.

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

Sidebar

Related Questions

I need to show a date in a certain format on screen, but I
I need some help to build SQL Query. I have table having data like:
I need to build an MySQL query and I want to try with django
I use a proprietary date format that looks like this: var TheUserDate = 3.11.2012.4.3;
I have date of this format March 3, 2011 in database and I need
I need to build a primary key consisting of 3 sections. The first section
I need to build a dynamic linq query with or operators. I have seen
I need to build a PDF based on FDF. I saw that Adobe has
I need to build a content gathering program that will simply read numbers on
I need to build my QT console application as 64 bit. i.e. x86_64 My

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.