Java中的OffsetTime類的from()方法從時態對象獲取OffsetTime的實例,該對象在方法的參數中傳遞。
用法:
public static OffsetTime from(TemporalAccessor temporal)
參數:此方法接受單個強製性參數temporal,該參數指定要轉換的時間對象,並且不為null。
返回值:它返回偏移時間,而不是null。
以下示例程序旨在說明from()方法:
示例1:
// Java program to demonstrate the from() method
import java.time.OffsetTime;
import java.time.ZonedDateTime;
public class GFG {
public static void main(String[] args)
{
// Function called to get current time
OffsetTime time
= OffsetTime.from(ZonedDateTime.now());
// Prints the current time
System.out.println("Current-time: "
+ time);
}
}
輸出:
Current-time: 13:07:59.941Z
程序2:
// Java program to demonstrate the from() method
import java.time.OffsetTime;
import java.time.ZonedDateTime;
public class GFG {
public static void main(String[] args)
{
// Function called to get current time
OffsetTime time
= OffsetTime.from(ZonedDateTime.now());
// Prints the current time
System.out.println("Current-time: "
+ time);
}
}
輸出:
Current-time: 13:08:03.087Z
相關用法
- Java OffsetTime until()用法及代碼示例
- Java OffsetTime get()用法及代碼示例
- Java OffsetTime plus()用法及代碼示例
- Java OffsetTime now()用法及代碼示例
- Java OffsetTime with()用法及代碼示例
- Java OffsetTime isBefore()用法及代碼示例
- Java OffsetTime format()用法及代碼示例
- Java OffsetTime toLocalTime()用法及代碼示例
- Java OffsetTime minus()用法及代碼示例
- Java OffsetTime minusSeconds()用法及代碼示例
- Java OffsetTime minusMinutes()用法及代碼示例
- Java OffsetTime isEqual()用法及代碼示例
- Java OffsetTime range()用法及代碼示例
- Java OffsetTime minusHours()用法及代碼示例
- Java OffsetTime plusMinutes()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetTime from() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。