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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:35:47+00:00 2026-05-31T16:35:47+00:00

I like to format the local timeformat into a string without the year. At

  • 0

I like to format the local timeformat into a string without the year. At the moment I am able to show the local format containing the year:

java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT);
String dateString = df.format(date);

therefore i receive an time string output like

12.03.2012
03/12/2012

for the different countries. Now i like to get a short form like

12.03.
03/12

how would i do this?

thanks for your help!

  • 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-31T16:35:48+00:00Added an answer on May 31, 2026 at 4:35 pm

    You can use SimpleDateFormat:

    Date date = new Date();
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("MM/dd");
    String dateString = df.format(date);
    

    Output:

    03/15
    

    EDIT:

    After researching locale formats further, and expanding on Peters answer, here’s some code to demonstrator differences between toPattern() and toLocalizedPattern():

    import java.text.*
    import java.util.*
    
    ArrayList<Locale> locales = new ArrayList<Locale>();
    locales.add(Locale.US);
    locales.add(Locale.UK);
    locales.add(Locale.GERMANY);
    locales.add(Locale.CHINA);
    
    Date date = new Date();
    
    for(Locale l : locales)
    {
        SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT, l);
        String pattern = sdf.toPattern();
        String localizedPattern = sdf.toLocalizedPattern()
        println "country: " + l.getDisplayName();
        println "pattern: " + pattern;
        println "localizedPattern: " + localizedPattern;
    
        try {
            SimpleDateFormat temp = new SimpleDateFormat(localizedPattern, l);
            println "localized pattern re-parsed successfully"
        } catch (IllegalArgumentException e) {
            println "localized pattern re-parsed unsuccessfully: " + e.getMessage();
        }
        SimpleDateFormat df = new SimpleDateFormat(pattern, l);
        String dateString = df.format(date);
        println "resulting date: " + dateString
        String yearlessPattern = pattern.replaceAll("\\W?[Yy]+\\W?", "");
        println "yearlessPattern = " + yearlessPattern;
        SimpleDateFormat yearlessSDF = new SimpleDateFormat(yearlessPattern, l);
        println "resulting date without year: " + yearlessSDF.format(date) + "\n";
    }
    

    Produces following output:

    country: English (United States)
    pattern: M/d/yy
    localizedPattern: M/d/yy
    localized pattern re-parsed successfully
    resulting date: 3/15/12
    yearlessPattern = M/d
    resulting date without year: 3/15
    
    country: English (United Kingdom)
    pattern: dd/MM/yy
    localizedPattern: dd/MM/yy
    localized pattern re-parsed successfully
    resulting date: 15/03/12
    yearlessPattern = dd/MM
    resulting date without year: 15/03
    
    country: German (Germany)
    pattern: dd.MM.yy
    localizedPattern: tt.MM.uu
    localized pattern re-parsed unsuccessfully: Illegal pattern character 't'
    resulting date: 15.03.12
    yearlessPattern = dd.MM
    resulting date without year: 15.03
    
    country: Chinese (China)
    pattern: yy-M-d
    localizedPattern: aa-n-j
    localized pattern re-parsed unsuccessfully: Illegal pattern character 'n'
    resulting date: 12-3-15
    yearlessPattern = M-d
    resulting date without year: 3-15
    

    So in conclusion, to display a localized date without a year:

    String yearlessPattern = DateFormat.getDateInstance(DateFormat.SHORT).toPattern().replaceAll("\\W?[Yy]+\\W?", "");

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

Sidebar

Related Questions

How does Stack Overflow show the revision changes in the diff-like format they use?
When we convert like String.Format({0:C}, 126.45) it returns $126.45 but if we convert like
I have text like this format term: 156^^^:^^59 datainput Or term: 156^^^:59 datainput or
I've got a String of a date/time in ISO-8601 format, like: 2011-04-15T20:08:18Z I want
I would like to return the local time as string but with leading zeros.
I have a timestamp with timezone information in string format and I would like
I would like to set some initial variables (like format compact and the current
So I have a list box that displays averages in a table like format
I would like to format a price in JavaScript. I'd like a function which
I'd like to format a duration in seconds using a pattern like H:MM:SS. The

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.