📌  相关文章
📜  Java中的 OffsetTime atDate() 方法及示例

📅  最后修改于: 2022-05-13 01:54:43.215000             🧑  作者: Mango

Java中的 OffsetTime atDate() 方法及示例

Java中 OffsetTime 类的atDate()方法将这个时间与一个日期结合起来创建一个 OffsetDateTime。

句法 :

public OffsetDateTime atDate(LocalDate date)

参数:此方法接受单个参数date ,它指定要结合的日期,而不是 null。

返回值:返回此时和指定日期形成的OffsetDateTime,不为null

下面的程序说明了 atDate() 方法:

程序 1:

// Java program to demonstrate the atDate() method
  
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
  
public class GFG {
    public static void main(String[] args)
    {
        // parses the current date
        LocalDate date = LocalDate.now();
        System.out.println("Current date: " + date);
  
        // Parses the current time
        OffsetTime time = OffsetTime.parse("11:10:10+06:03");
        OffsetDateTime datetime = time.atDate(date);
        System.out.println("Current date and time: " + datetime);
    }
}
输出:
Current date: 2018-12-31
Current date and time: 2018-12-31T11:10:10+06:03

方案二

// Java program to demonstrate the atDate() method
  
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
  
public class GFG {
    public static void main(String[] args)
    {
        // parses the current date
        LocalDate date = LocalDate.now();
        System.out.println("Current date: " + date);
  
        // Parses the current time
        OffsetTime time = OffsetTime.parse("12:15:14+16:03");
        OffsetDateTime datetime = time.atDate(date);
        System.out.println("Current date and time: " + datetime);
    }
}
输出:
Current date: 2018-12-31
Current date and time: 2018-12-31T12:15:14+16:03

参考:https: Java/time/OffsetTime.html#atDate-java.time.LocalDate-