Unable to parse date String to Date

后端 未结 2 514
旧巷少年郎
旧巷少年郎 2021-01-18 02:26

im want to parse a date String to a Date. I was looking in some other questions, but I didn\'t find an answer.

String mail_delivered = \"31.10.2013 17:57:58          


        
相关标签:
2条回答
  • 2021-01-18 02:47

    Try This:

    public static void main(String[] args)throws Exception {
            // TODO Auto-generated method stub
           //Middle European Time (MET or MEZ-German)
            String mail_delivered = "31.10.2013 17:57:58 MET";
            try {
                SimpleDateFormat df= new SimpleDateFormat("dd.MM.yyyy HH:mm:ss z",Locale.GERMAN);
                Date result =  df.parse(mail_delivered);  
                System.out.println(result);
            } catch (ParseException pe) {
                pe.printStackTrace();
            }
        }
    

    Output :- Thu Oct 31 22:27:58 IST 2013

    0 讨论(0)
  • 2021-01-18 02:56

    In German, "Central European Time" is "Mitteleuropäische Zeit", so if you want to use Locale.GERMAN, change CET to MEZ and it works.

    String mail_delivered = "31.10.2013 17:57:58 MEZ";
    

    For a list of all the legal time zone strings for a given locale, use this:

    DateFormatSymbols.getInstance(Locale.GERMAN).getZoneStrings()
    
    0 讨论(0)
提交回复
热议问题