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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:12:11+00:00 2026-06-14T09:12:11+00:00

public static void main(String[] args) throws ParseException { List<String> strd = new ArrayList<>(); List<Date>

  • 0
 public static void main(String[] args) throws ParseException {
        List<String> strd = new ArrayList<>();
        List<Date> date = new ArrayList<>();
        strd.add("Sun May 11 03:17:40 UTC 2009");
        strd.add("Wed Jun 11 03:17:40 UTC 2008");
        strd.add("Mon May 11 03:17:40 UTC 2009");
        strd.add("Mon Jun 11 03:17:40 UTC 2009");
        strd.add("Sun Jun 11 03:17:40 UTC 2009");
        List<Character> letters = new ArrayList<>();
        char letter;
        for (letter = 'A'; letter <= 'Z'; letter++) {
            letters.add(letter);
        }
        List<String> dateToChar = new ArrayList<>();

        for (int j = 0; j < strd.size(); j++) {
            try {
                String strDate = strd.get(j);
                // String strDate = "Mon May 11 03:17:40 UTC 2009";
                SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
                Date dateStr = formatter.parse(strDate);
                String formattedDate = formatter.format(dateStr);
                System.out.println("Date is ==>" + formattedDate);
                Date date1 = formatter.parse(formattedDate);
                date.add(date1);
            } catch (ParseException e) {
                System.err.print(e);
            }
        }

        for (int k = 0; k < date.size(); k++) {
            for (int h = 1; h < date.size(); h++) {
                if (k != h && k < h) {
                    if (date.get(k).equals(date.get(h))) {
                        System.out.println("Equal dates");                        
                    } else {

                        System.out.println("Not Equal dates");
                    }
                }
            }
        }        
    }
}

My problem is that when I do the parsing, the output is:

Date is ==>Mon May 11 03:17:40 UTC 2009
Date is ==>Wed Jun 11 03:17:40 UTC 2008
Date is ==>Mon May 11 03:17:40 UTC 2009
Date is ==>Thu Jun 11 03:17:40 UTC 2009
Date is ==>Thu Jun 11 03:17:40 UTC 2009
Not Equal dates
Equal dates
Not Equal dates
Not Equal dates
Not Equal dates
Not Equal dates
Not Equal dates
Not Equal dates
Not Equal dates
Equal dates

Why? I cannot understand the reason! The last dates are wrong, but only the last ones. If I change the date, for example, the output is wrong again.

  • 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-14T09:12:12+00:00Added an answer on June 14, 2026 at 9:12 am

    The results in your print out look correct to me as the Day of Week is not being used by the date parser. If the only difference between two of the strings is the day of the week, then they will parse to the same date value.

    First pass thru loop:

    "Sun May 11 03:17:40 UTC 2009" vs "Wed Jun 11 03:17:40 UTC 2008" == not equal month
    "Sun May 11 03:17:40 UTC 2009" vs "Mon May 11 03:17:40 UTC 2009" == equal (DoW ignored)
    "Sun May 11 03:17:40 UTC 2009" vs "Mon Jun 11 03:17:40 UTC 2009" == not equal month
    "Sun May 11 03:17:40 UTC 2009" vs "Sun Jun 11 03:17:40 UTC 2009" == not equal month
    

    Second pass thru loop:

    "Wed Jun 11 03:17:40 UTC 2008" vs "Mon May 11 03:17:40 UTC 2009" == not equal month
    "Wed Jun 11 03:17:40 UTC 2008" vs "Mon Jun 11 03:17:40 UTC 2009" == not equal year
    "Wed Jun 11 03:17:40 UTC 2008" vs "Sun Jun 11 03:17:40 UTC 2009" == not equal year
    

    Third pass thru loop:

    "Mon May 11 03:17:40 UTC 2009" vs "Mon Jun 11 03:17:40 UTC 2009" == not equal month
    "Mon May 11 03:17:40 UTC 2009" vs "Sun Jun 11 03:17:40 UTC 2009" == not equal month
    

    Fourth and final pass thru loop:

    "Mon Jun 11 03:17:40 UTC 2009" vs "Sun Jun 11 03:17:40 UTC 2009" == equal (DoW ignored)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public static void main(String[] args) throws Exception { RSAKeyPairGenerator rsaKeyPairGen = new RSAKeyPairGenerator(); AsymmetricCipherKeyPair
public static void main(String[] args) throws IOException { String st3[]=new String[]{сто, двести, триста, sdf,
public static void main(String[] args) throws Exception { Socket socket = new Socket(127.0.0.1, 2345);
public class L20 { public static void main(String[] args) throws IOException{ Scanner input=new Scanner(System.in);
public static void main(String[] args) throws IOException, URISyntaxException,TransformerException { TransformerFactory factory = TransformerFactory.newInstance(); String
class Test { public static void main(String[] args) throws Exception { Test t =
Following is my consumer : public static void main(String[] args) throws JMSException { //
as the title. public static void main(String[] args) throws InterruptedException { Thread thread =
import javax.swing.*; public class test { public static void main(String[] args) throws Exception {
import java.io.*; import java.util.*; public class Readfilm { public static void main(String[] args) throws

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.