博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java 根据类名示例化类_Java即时类| EpochSecond()方法的示例
阅读量:2531 次
发布时间:2019-05-11

本文共 3743 字,大约阅读时间需要 12 分钟。

java 根据类名示例化类

EpochSecond()方法的即时类 (Instant Class ofEpochSecond() method)

Syntax:

句法:

public static Instant ofEpochSecond(long sec_val);    public static Instant ofEpochSecond(long sec_val, long nanos_adjust);
  • ofEpochSecond() method is available in java.time package.

    ofEpochSecond()方法在java.time包中可用。

  • ofEpochSecond(long sec_val) method is used to represent an instance of this Instant by using the given seconds from the java epoch standard format since 1970-01-01T00:00:00Z.

    ofEpochSecond(long sec_val)方法用于表示此Instant的实例, 方法是使用从1970-01-01T00:00:00Z开始的java epoch标准格式的给定秒数。

  • ofEpochSecond(long sec_val, long nanos_adjust) method is used to represent an instance of this Instant by using the given seconds and nano fraction of seconds from the java epoch of 1970-01-01T00:00:00Z.

    ofEpochSecond(long sec_val,long nanos_adjust)方法用于通过使用距1970-01-01T00:00:00Z的java纪元的给定秒数和秒的毫微秒数来表示此Instant的实例。

  • These methods may throw an exception at the time of representing seconds in epoch format.

    这些方法在以纪元格式表示秒时可能会引发异常。

    DateTimeException: This exception may throw when this Instant value reaches out of the min or max instant.

    DateTimeException :当此Instant值超出最小或最大瞬时值时,可能引发此异常。

  • These are static methods and it is accessible with class name and if we try to access these methods with class object then we will not get an error.

    这些是静态方法,可通过类名进行访问,如果尝试使用类对象访问这些方法,则不会出错。

Parameter(s):

参数:

  • In the first case, "ofEpochSecond(long sec_val)",

    在第一种情况下,“ ofEpochSecond(long sec_val)”,

    • long sec_val – represents the number of seconds in value since 1970-01-01T00:00:00Z.
    • long sec_val –表示自1970-01-01T00:00:00Z以来的秒数。
  • In the second case, "ofEpochSecond(long sec_val, long nanos_adjust)",

    在第二种情况下,“ ofEpochSecond(long sec_val,long nanos_adjust)”,

    • long sec_val – Similar as defined in the first case.
    • long sec_val –与第一种情况中定义的类似。
    • long nanos_adjust – represents the adjustment when the second reaches out of range.
    • long nanos_adjust –表示秒数超出范围时的调整。

Return value:

返回值:

In both the cases, the return type of the method is Instant,

在这两种情况下,方法的返回类型均为Instant 。

  • In the first cases, it returns the Instant that represent the given seconds.

    在第一种情况下,它返回代表给定秒数的Instant。

  • In the second cases, it returns the Instant that represent the given seconds and nano fraction of seconds.

    在第二种情况下,它返回表示给定秒数和秒的毫微秒数的Instant。

Example:

例:

// Java program to demonstrate the example // of ofEpochSecond() method of Instantimport java.time.*;import java.time.temporal.*;public class OfEpochSecondOfInstant {
public static void main(String args[]) {
long epoch_sec = 25; long nanos_adjust = 25000; // Instantiates two Instant Instant ins1 = Instant.parse("2006-04-03T05:10:15.00Z"); Instant ins2 = Instant.now(); // Display ins1,ins2 System.out.println("Instant ins1 and ins2: "); System.out.println("ins1: " + ins1); System.out.println("ins2: " + ins2); System.out.println(); // Here, this method represents the given second // from the java epoch of 1970-01-01T00:00:00Z Instant of_epoch_sec = ins1.ofEpochSecond(epoch_sec); // Display of_epoch_sec System.out.println("ins1.ofEpochSecond(epoch_sec): " + of_epoch_sec); // Here, this method represents the instant by using // seconds and nanoseconds from the java epoch // of 1970-01-01T00:00:00Z of_epoch_sec = ins2.ofEpochSecond(epoch_sec, nanos_adjust); // Display of_epoch_sec System.out.println("ins2.ofEpochSecond(epoch_sec,nanos_adjust): " + of_epoch_sec); }}

Output

输出量

Instant ins1 and ins2: ins1: 2006-04-03T05:10:15Zins2: 2020-05-28T07:12:35.393208Zins1.ofEpochSecond(epoch_sec): 1970-01-01T00:00:25Zins2.ofEpochSecond(epoch_sec,nanos_adjust): 1970-01-01T00:00:25.000025Z

翻译自:

java 根据类名示例化类

转载地址:http://gixzd.baihongyu.com/

你可能感兴趣的文章
Zico源代码分析:执行启动过程分析和总结
查看>>
Android之Http通信——1.初识Http协议
查看>>
hdu5044(二分)
查看>>
静态路由、缺省路由的作用
查看>>
linux快捷键绝对路径相对路径讲解
查看>>
又漏一次
查看>>
dede模板中plus文件路径使用方法
查看>>
xml解析demo使用
查看>>
python使用模板手记
查看>>
No result defined for action com.nynt.action.ManageAction and result input问题
查看>>
iOS开发拓展篇—UIDynamic(重力行为+碰撞检测)
查看>>
洛谷 P3627 [APIO2009](抢掠计划 缩点+spfa)
查看>>
c++ 连接数据库
查看>>
函数指针与回调函数
查看>>
你所不知道的 CSS 滤镜技巧与细节
查看>>
hack reviewboard 让 FireFox 把 tab 显示为 4 或 2 个空格
查看>>
css 学习整理
查看>>
录制游戏视频——fraps
查看>>
jQuery 停止动画
查看>>
HTML基础之JS
查看>>