php做网站软件,wordpress安装论坛,网站在建设中是什么意思,软件工程师报考条件Java中OffsetDateTime类的withHour()方法返回此OffsetDateTime的副本#xff0c;其中一天中的小时数按照参数中的指定进行了更改。用法:public OffsetDateTime withHour(int hour)参数#xff1a;此方法接受单个参数hour#xff0c;该参数指定要在结果中设置的一天中的小时其中一天中的小时数按照参数中的指定进行了更改。用法:public OffsetDateTime withHour(int hour)参数此方法接受单个参数hour该参数指定要在结果中设置的一天中的小时范围从0到23。返回值它基于此日期返回OffsetDateTime并带有一天中的请求时间而不是null。异常当一天中的小时值无效或day-of-year无效时程序将引发DateTimeException。以下示例程序旨在说明withHour()方法示例1:// Java program to demonstrate the withHour() methodimport java.time.OffsetDateTime;import java.time.ZonedDateTime;public class GFG {public static void main(String[] args){// Parses the date1OffsetDateTime date1 OffsetDateTime.parse(2018-12-12T13:30:3005:00);// Prints datesSystem.out.println(Date1: date1);// Changes the hour of daySystem.out.println(Date1 after altering hour of the day: date1.withHour(20));}}输出Date1: 2018-12-12T13:30:3005:00Date1 after altering hour of the day: 2018-12-12T20:30:3005:00示例2:// Java program to demonstrate the withHour() methodimport java.time.OffsetDateTime;public class GFG {public static void main(String[] args){try {// Parses the date1OffsetDateTime date1 OffsetDateTime.parse(2018-12-12T13:30:3005:00);// Prints datesSystem.out.println(Date1: date1);// Changes the hour of daySystem.out.println(Date1 after altering hour of the day: date1.withHour(27));}catch (Exception e) {System.out.println(Exception: e);}}}输出Date1: 2018-12-12T13:30:3005:00Exception: java.time.DateTimeException:Invalid value for HourOfDay (valid values 0 - 23): 27