CopyPastor

Detecting plagiarism made easy.

Score: 0.8630434058863541; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2018-08-22
by Rishav Singla

Original Post

Original - Posted on 2013-06-01
by assylias



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Your pattern does not correspond to the input string at all... It is not surprising that it does not work. This would probably work better:
SimpleDateFormat sdf = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH); Then to print with your required format you need a second SimpleDateFormat:
Date parsedDate = sdf.parse(date); SimpleDateFormat print = new SimpleDateFormat("MMM d, yyyy HH:mm:ss"); System.out.println(print.format(parsedDate)
Your pattern does not correspond to the input string at all... It is not surprising that it does not work. This would probably work better:
SimpleDateFormat sdf = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
Then to print with your required format you need a second SimpleDateFormat:
Date parsedDate = sdf.parse(date); SimpleDateFormat print = new SimpleDateFormat("MMM d, yyyy HH:mm:ss"); System.out.println(print.format(parsedDate));
Notes:
- you should include the locale as if your locale is not English, the day name might not be recognised - [IST is ambiguous and can lead to problems][1] so you should use the proper time zone name if possible in your input.
[1]: https://stackoverflow.com/questions/11264697/java-timezone-strange-behavior-with-ist

        
Present in both answers; Present only in the new answer; Present only in the old answer;