Java simpledateformat parses timezones, such as America / Los_ Angeles
•
Java
I want to parse the following string in Java and convert it to a date:
DTSTART;TZID=America/Los_Angeles:201@R_403_2407@23T120000
I tried this:
SimpleDateFormat sdf = new SimpleDateFormat("'DTSTART;TZID='Z':'yyyyMMdd'T'hhmmss"); Date start = sdf.parse("DTSTART;TZID=America/Los_Angeles:201@R_403_2407@23T120000");
And this:
SimpleDateFormat sdf = new SimpleDateFormat("'DTSTART;TZID='z':'yyyyMMdd'T'hhmmss"); Date start = sdf.parse("DTSTART;TZID=America/Los_Angeles:201@R_403_2407@23T120000");
But it still doesn't work I think the problem is America / Los_ Angeles. Can you help me?
thank you
Solution
Try this with timezone
Note: you must split the date string before performing this operation
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'hhmmss"); TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); sdf.setTimeZone(tz); Date start = sdf.parse("201@R_403_2407@23T120000");
In simpledateformat mode, Z represents RFC 822 4-bit time zone
For more information, see simpledateformat #timezone
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码