Java – try to parse the date time in PDT into zoneddatetime representation
                                        
                    •
                    Java                                    
                How can I parse the date time value in the PDT time zone?
06/24/2017 07:00 AM (PDT)
I want to maintain time zones so that I can represent the time in other time zones according to the preferences of website visitors
I tried to use zoneddatetime, but I got a parsing error:
java.time.zoneddatetime.parse("06/24/2017 07:00 AM (PDT)")
The error is:
java.time.format.DateTimeParseException: Text '06/24/2017 07:00 AM (PDT)' Could not be parsed at index 0 at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) at java.time.zoneddatetime.parse(zoneddatetime.java:597) at java.time.zoneddatetime.parse(zoneddatetime.java:582) ... 29 elided
Also, do you agree that I should use zoned datetime?
Solution
Since your format is non-standard, you need to assign it to the parser:
zoneddatetime.parse(
    "06/24/2017 07:00 AM (PDT)",DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm a (zzz)")
);
                
                            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
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        