Java SimpleDateFormat parse Timezone like America/Los_Angeles

后端 未结 2 517
[愿得一人]
[愿得一人] 2020-12-19 15:07

I want to parse the following string in Java and convert it to a date:

DTSTART;TZID=America/Los_Angeles:20140423T120000

I tried this:

2条回答
  •  孤城傲影
    2020-12-19 16:00

    Try this one using TimeZone.

    Note: You have to split your date string before doing this operation.

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'hhmmss");
    
        TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
        sdf.setTimeZone(tz);
    
        Date start = sdf.parse("20140423T120000");
    

    In SimpleDateFormat pattern Z represent RFC 822 4-digit time zone

    For more info have a look at SimpleDateFormat#timezone.

提交回复
热议问题