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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:55:04+00:00 2026-06-09T12:55:04+00:00

I use SimpleDataFormat for years. I never get this Exception the program is below,

  • 0

I use SimpleDataFormat for years. I never get this Exception

the program is below, I got this code of an example from the internet:

    public static void main(String[] args) {
    // Make a new Date object. It will be initialized to the
    // current time.
    Date now = new Date();

    // Print the result of toString()
    String dateString = now.toString();
    System.out.println(" 1. " + dateString);

    // Make a SimpleDateFormat for toString()'s output. This
    // has short (text) date, a space, short (text) month, a space,
    // 2-digit date, a space, hour (0-23), minute, second, a space,
    // short timezone, a final space, and a long year.
    SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");

    // See if we can parse the output of Date.toString()
    try {
        Date parsed = format.parse(dateString);
        System.out.println(" 2. " + parsed.toString());
    }
    catch(ParseException pe) {
        System.out.println("ERROR: Cannot parse \"" + dateString + "\"");
    }

    // Print the result of formatting the now Date to see if the result
    // is the same as the output of toString()
    System.out.println(" 3. " + format.format(now));
}

Ok pretty Simple.

The result:

 1. Wed Aug 08 13:49:05 BRT 2012
    ERROR: Cannot parse "Wed Aug 08 13:49:05 BRT 2012"
 3. Qua Ago 08 13:49:05 BRT 2012

You see that the 2. thrown an error? For me it’s everything correct.

Is there any locale stuff I should set?

My O.S: Windows 7 Proffesional, Service Pack 1
JDK: jdk1.6.0_25

  • 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-09T12:55:06+00:00Added an answer on June 9, 2026 at 12:55 pm

    It looks like it’s a locale issue, yes. If you look at the output, it’s not using English month and day names – so it wouldn’t be able to parse them either. Try specifying English when you create the SimpleDateFormat:

    SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",
                                                   Locale.US);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I execute this code in plain java and in android, I get different
I have my time in the below format, and I use this value to
We can't use java.text.SimpleDateFormat, so is there any way to create date object from
use strict; use warnings; use Time::HiRes qw(sleep); use Test::WWW::Selenium; use Test::More no_plan; use Test::Exception;
I have this as a string 02/06/2012 1:25 PM EST I want to use
I am trying to use the Android SimpleDateFormat like this: String _Date = 2010-09-29
I cannot use Joda. When I try to create a Date or Calendar from
I use this pattern SimpleDateFormat format = new SimpleDateFormat(YYYY-MM-dd HH:mm:ss); in windows and it
For my app I use a sunriseCalc-lib. This lib calculates the sunrise-time and returns
I have this method to test : public static Date getDateSinceUTC(CstOrderBean orderBean) { int

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.