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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:59:31+00:00 2026-05-21T06:59:31+00:00

I am trying to convert a string to proper date format using Java’s SimpleDateFormat

  • 0

I am trying to convert a string to proper date format using Java’s SimpleDateFormat. For some reason, it’s not working with certain months like “Mar”, “May”, “Oct”, and “Dec.” Can somebody help me? It works fine for all other months.

import java.sql.Date;
import java.text.SimpleDateFormat;

import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;

public class test {
    public static void main(String args[]) throws java.text.ParseException {
        try {
            SimpleDateFormat parse = new SimpleDateFormat("dd. MMM yyyy hh:mm:ss");
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            //why this doesn't work with certain months like Mar, May, Oct, and Dec? otherwise it works fine

            String dateTime =   "01. Jun 2010 15:30:32";
            //String dateTime = "07. Mar 2011 15:20:10";
            //String dateTime = "07. May 2011 15:20:10";
            //String dateTime = "07. Oct 2011 15:20:10";
            //String dateTime = "07. Dec 2011 15:20:10";


            java.util.Date parsed =parse.parse(dateTime);
            System.out.println("formatted: " + formatter.format(parsed));
        } catch(ParseException e) {
            System.out.println("Caught " + e);
        } 
    }
}    
  • 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-21T06:59:32+00:00Added an answer on May 21, 2026 at 6:59 am

    You need to set the locale on SimpleDateFormat, otherwise the platform default locale will be used for month names. You can do that by passing it as 2nd argument to the SimpleDateFormat constructor. If you want to work with English formatted month names, pass Locale.ENGLISH.

    new SimpleDateFormat("dd. MMM yyyy hh:mm:ss", Locale.ENGLISH);
    

    By the way, you can learn about your platform default locale by

    System.out.println(Locale.getDefault());
    

    This is configureable at OS level (in Windows control panel, for example) and as JVM argument.

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

Sidebar

Related Questions

I'm trying to convert a string into a date format My string looks like
I'm trying to convert a date string into an age. The string is like:
I was trying to use TextInfo.ToTitleCase to convert some names to proper case. it
I am trying to convert a standard std::string into an NSString but I'm not
I am trying to convert a string of this format: MM/dd/yyyy HH:mm The input
I'm trying to convert a string date value from a submitted form into an
Am trying to convert a String value to long, and am getting : java.lang.NumberFormatException:
i trying to convert time in string format to minutes. i can use substring
I am trying to take the string <BR> in VB.NET and convert it to
I'm trying to convert some strings that are in French Canadian and basically, I'd

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.