Parsing from string to date
I am a little lost here , I think i do everything ok and it still does not work 开发者_开发知识库(PaseException
String time = "Fri Apr 15 14:29:57 IDT 2011";
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
sdf.parse(time);
Help highly appreciated!
String time = "Fri Apr 15 14:29:57 IDT 2011";
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
System.out.println(sdf.parse(time));
Works fine for me.!
May be you can try with
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy",Locale.ENGLISH);
Your default locale is not compatible with this date pattern.
Try:
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy", Locale.ENGLISH);
(I confirmed this as working)
add locale as second constructor parameter:
String time = "Fri Apr 15 14:29:57 IDT 2011";
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy", Locale.ENGLISH);
System.out.println(sdf.parse(time));
精彩评论