java 根据类名示例化类_Java即时类| EpochSecond()方法的示例
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,ins2System.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:00ZInstant of_epoch_sec = ins1.ofEpochSecond(epoch_sec);// Display of_epoch_secSystem.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:00Zof_epoch_sec = ins2.ofEpochSecond(epoch_sec, nanos_adjust);// Display of_epoch_secSystem.out.println("ins2.ofEpochSecond(epoch_sec,nanos_adjust): " + of_epoch_sec);} }Output
輸出量
Instant ins1 and ins2: ins1: 2006-04-03T05:10:15Z ins2: 2020-05-28T07:12:35.393208Zins1.ofEpochSecond(epoch_sec): 1970-01-01T00:00:25Z ins2.ofEpochSecond(epoch_sec,nanos_adjust): 1970-01-01T00:00:25.000025Z翻譯自: https://www.includehelp.com/java/instant-ofepochsecond-method-with-example.aspx
java 根據類名示例化類
總結
以上是生活随笔為你收集整理的java 根据类名示例化类_Java即时类| EpochSecond()方法的示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 黄褐斑治疗多少钱啊?
- 下一篇: 苹果四多少钱啊?