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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:13:24+00:00 2026-06-04T18:13:24+00:00

Ok, so I have a string, say Tue May 21 14:32:00 GMT 2012 I

  • 0

Ok, so I have a string, say “Tue May 21 14:32:00 GMT 2012” I want to convert this string to local time in the format May 21, 2012 2:32 pm. I tried SimpleDateFormat(“MM dd, yyyy hh:mm a”).parse(), but it threw an exception. So what should I do?

The exception is “unreported exception java.text.ParseException; must be caught or declared to be thrown.”

in the line Date date = inputFormat.parse(inputText);

The code I ran on TextMate:

public class test{
    public static void main(String arg[]) {
        String inputText = "Tue May 22 14:52:00 GMT 2012";
        SimpleDateFormat inputFormat = new SimpleDateFormat(
            "EEE MMM dd HH:mm:ss 'GMT' yyyy", Locale.US);
        inputFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
        SimpleDateFormat out = new SimpleDateFormat("MMM dd, yyyy h:mm a");
        Date date = inputFormat.parse(inputText);
        String output = out.format(date);
       System.out.println(output);
    }
}
  • 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-04T18:13:25+00:00Added an answer on June 4, 2026 at 6:13 pm

    The format string you provided for parsing doesn’t correspond with the text format you’ve actually got. You need to parse first, then format. It looks like you want:

    SimpleDateFormat inputFormat = new SimpleDateFormat(
        "EEE MMM dd HH:mm:ss 'GMT' yyyy", Locale.US);
    inputFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
    
    SimpleDateFormat outputFormat = new SimpleDateFormat("MMM dd, yyyy h:mm a");
    // Adjust locale and zone appropriately
    
    Date date = inputFormat.parse(inputText);
    String outputText = outputFormat.format(date);
    

    EDIT: Here’s the same code in the form of a short but complete program, with your sample input:

    import java.util.*;
    import java.text.*;
    
    public class Test {
        public static void main(String[] args) throws ParseException {
            String inputText = "Tue May 21 14:32:00 GMT 2012";
            SimpleDateFormat inputFormat = new SimpleDateFormat
                ("EEE MMM dd HH:mm:ss 'GMT' yyyy", Locale.US);
            inputFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
    
            SimpleDateFormat outputFormat =
                new SimpleDateFormat("MMM dd, yyyy h:mm a");
            // Adjust locale and zone appropriately
            Date date = inputFormat.parse(inputText);
            String outputText = outputFormat.format(date);
            System.out.println(outputText);
        }
    }
    

    Can you compile and run that exact code?

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

Sidebar

Related Questions

I have a String variable say strHTML = <div class='abc'> This is a test
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have a string like this: String test = hfikoebndolahsdHEL123LOkjahhsdqhuihs; And then
Let's say I have a string This $0 is $2 $1. Still, \$$3 is
Lets say a have a string such as this one: string txt = Lore
Let's say I have this string var: string strData = 1|2|3|4||a|b|c|d Then, I make
Let's say I have this string: Hello &, how are you? I'm fine! Is
I have a string like this: 'say Twenty-five minutes remaining.' How would I interpolate
I have a String say String s = |India| vs Aus; In this case
Lets say I have string like this: String q = foo (one) bla (two)

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.