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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。