I am using the ZonedDateTime with DateTimeFormatter of Java 8. When I try to parse my own pattern it doesn\'t recognizes and throws an exception.
String
Here is an small example of using the ZonedDateTime with DateTimeFormatter of Java 8.
public String currentDateTime() {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("EEEE y-MM-d MMMM HH:m:s z Z'['VV']' 'Day:'D");
return ZonedDateTime.now(ZoneId.of("Europe/Lisbon")).format(dateTimeFormatter);
}
The ZonedDateTime class permits you to create a date/time object with a time zone. The default time zone will be used; i.e., the time zone you have established on your computer. You can use the DateTimeFormatter class to display the time zone. In the Java code, the time zone is displayed as zone offset, zone name and zone ID. Note that the date time formatter pattern is "Z", "z", and "VV", respectively. The program also creates a date/time object and then adds the zone ID using the of method of the ZoneId class. Finally, a time zone is added to another date/time object using the of method of the ZoneOffset class.