4

i have this string output 'Wed Apr 01 09:50:31 CEST 2015' can anyone tell me what pattern is that . i need it in order to use it in another function.

@Test
public void test() throws ParseException {
    String input = "Wed Apr 01 09:50:31 CEST 2015";
    String format = "DD MM hh:mm:ss YYYY"; // i have a wrong format

    SimpleDateFormat df = new SimpleDateFormat(format);
    Date date = df.parse(input);

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int week = cal.get(Calendar.WEEK_OF_YEAR);
    System.out.println(week);
}

any help to figure out the correct format of date pattern in my case.

Gilles
  • 202
  • 1
  • 11
Nedal Jedidi
  • 119
  • 1
  • 7

1 Answers1

3

Solution to your problem is to override default Date locale using

SimpleDateFormat(String pattern, Locale locale) constructor:

DateFormat dateFormat = new SimpleDateFormat(
        "EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
dateFormat.parse("Tue Jul 13 00:00:00 CEST 2011");
 System.out.println(dateFormat.format(new Date()));

Solution copy of How to convert a date in this format (Tue Jul 13 00:00:00 CEST 2010) to a Java Date (The string comes from an alfresco property)

Community
  • 1
  • 1
Distopic
  • 717
  • 3
  • 16
  • 31