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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:55:48+00:00 2026-05-27T18:55:48+00:00

Is it possible to retrieve a default pattern for a given locale, without casting

  • 0

Is it possible to retrieve a default pattern for a given locale, without casting an object returned by DateFormat.get*Instance() to a SimpleDateFormat?

I understand, that in most cases everything will be OK, but there is a note in javadoc, here: “If you want even more control over the format or parsing, (or want to give your users more control), you can try casting the DateFormat you get from the factory methods to a SimpleDateFormat. This will work for the majority of countries; just remember to put it in a try block in case you encounter an unusual one.”

So I wonder, what should I do in case I “encounter an unusual one“?

Related theme.

Code sample:

/**
 * Returns '\n'-separated string with available patterns.
 * Optional adds appropriate language code to each pattern string.
 * 
 * @param showLanguage Defines if language info is required.
 * @return  String with available patterns, optional (if showLanguage is set
 * to "true") adds appropriate language code to each pattern.
 */
public String getPatternsForAvailableLocales(Boolean... showLanguage) {

    /* Array of available locales */
    Locale[] locales = DateFormat.getAvailableLocales();

    String result = "";

    for (Locale locale : locales) {

        /* Add language info, if necessary */
        if ((showLanguage.length > 0) && (showLanguage[0])) {
            result += locale.getLanguage() + '\t';
        }

        /* Retrieving pattern */ 
        try {
            result += ((SimpleDateFormat)
                    DateFormat.getDateTimeInstance(DateFormat.SHORT,
                            DateFormat.SHORT, locale)).toPattern();
        } catch (ClassCastException e) {
            // ******************************** //
            // What's up? Is there another way? //
            // ******************************** //
        }

        result += '\n';

    }
    return result;
}
  • 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-27T18:55:49+00:00Added an answer on May 27, 2026 at 6:55 pm

    You can retrieve the date format symbols for a particular language by executing the following Java code:

    System.out.println(DateFormatSymbols.getInstance
            (new Locale("en_US")).getLocalPatternChars());
    System.out.println(DateFormatSymbols.getInstance
            (new Locale("nl_NL")).getLocalPatternChars());
    

    In this particular case, Dutch, the date format symbols are the same.

    GyMdkHmsSEDFwWahKzZ
    GyMdkHmsSEDFwWahKzZ
    

    In the event that the symbols for the foreign language are different, you substitute the foreign language character for the English character in the simple format string.

    The DateFormatSymbols class has existed since at least Java 1.4.2.

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

Sidebar

Related Questions

Is it possible to retrieve the caller instance of a method/constructor? This question has
Is it possible to retrieve items from a Python dictionary in the order that
Is it possible to retrieve variable set in onreadystatechange function from outside the function?
Is it possible to retrieve the underlying hostname/port from a new TcpClient? TcpListener listener
Is it possible to retrieve the geometric position (i.e. top/left offsets from either the
Is it possible to retrieve computer information (RAM, hard drive size, cpu speed, etc.)
is it possible to retrieve statistics about the minimal or maximal value of a
Is it possible to retrieve programmatically all the case of a switch ? I
is it possible to retrieve by using connection.getschema() the description item from a sql
I was wondering if it would be possible to retrieve the complete list of

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.