I want to parse the following string in Java and convert it to a date:
DTSTART;TZID=America/Los_Angeles:20140423T120000
I tried this:
SimpleDateFormat sdf = new SimpleDateFormat("'DTSTART;TZID='Z':'yyyyMMdd'T'hhmmss");
Date start = sdf.parse("DTSTART;TZID=America/Los_Angeles:20140423T120000");
And this:
SimpleDateFormat sdf = new SimpleDateFormat("'DTSTART;TZID='z':'yyyyMMdd'T'hhmmss");
Date start = sdf.parse("DTSTART;TZID=America/Los_Angeles:20140423T120000");
But it still doesn't work. I think the problem is in America/Los_Angeles. Can you help me please?
Thank you
If you look for a solution how to parse the whole given string in one and only one step then Java 8 offers this option (the pattern symbol V is not supported in
SimpleDateFormat
):Try this one using TimeZone.
Note: You have to split your date string before doing this operation.
In
SimpleDateFormat
patternZ
representRFC 822 4-digit time zone
For more info have a look at SimpleDateFormat#timezone.