Convert String to Date in java - Time zone

后端 未结 6 921
情书的邮戳
情书的邮戳 2020-12-21 12:34

I have a String, 2013-10-07T23:59:51.205-07:00, want to convert this to Java date object. I am getting parsing error.

date = new SimpleDateForma         


        
6条回答
  •  独厮守ぢ
    2020-12-21 13:37

    try

    date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
                     .parse("2013-10-07T23:59:51.205-0700");
    

    The Z is not a literal and the timezone does not have a colon

    See the examples at http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

    If java7 is being used then Z can be replaced with X and the timezone can have a colon

提交回复
热议问题