Parsing Date Formats in Java

后端 未结 2 1636
有刺的猬
有刺的猬 2021-01-29 05:30

I\'m trying to convert Dates into Unix Timestamps in Java. Examples for my dates are: \"Fri Jun 05 15:53:07 PDT 2009\"

My code is:

DateFormat dateFormat          


        
2条回答
  •  情话喂你
    2021-01-29 05:52

    You need to set Locale, Some cases if you are not set the locale you may face this kind of issues.

    Eg:

    DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"
                                                                         ,Locale.US);
    

    From Java doc.

    SimpleDateFormat also supports localized date and time pattern strings. In these strings, the pattern letters described above may be replaced with other, locale dependent, pattern letters. SimpleDateFormat does not deal with the localization of text other than the pattern letters; that's up to the client of the class.

提交回复
热议问题