Java 中的 Instant parse() 方法


可以透過 Java 中 Instant 類中的 toString() 方法獲得 Instant 的字串表示形式。此方法不需要引數,並會返回 Instant 的字串表示形式。

示例如下 −

示例

 線上演示

import java.time.*;
public class Demo {
   public static void main(String[] args) {
      Instant i = Instant.now();
      System.out.println("The current Instant is: " + i.toString());
   }
}

輸出

The current Instant is: 2019-02-13T09:01:52.484Z

現在讓我們瞭解一下上述程式。

使用 toString() 方法獲得當前 Instant 的字串表示形式。然後顯示該內容。展示此內容的程式碼片段如下 −

Instant i = Instant.now();
System.out.println("The current Instant is: " + i.toString());

上次更新:30-Jul-2019

242 次瀏覽

啟動您的 職業

透過完成課程獲得認證

開始
廣告