java.time.Instant.parse() 方法示例



說明

java.time.Instant.parse(CharSequence text) 方法從文字字串(比如 2007-12-03T10:15:30.00Z)獲取 Instant 例項。

宣告

下面是 java.time.Instant.parse(CharSequence text) 方法的宣告。

public static Instant parse(CharSequence text)

引數

text - 要解析的文字,非空。

返回值

瞬間,非空。

異常

DateTimeException - 如果無法解析文字。

示例

以下示例演示瞭如何使用 java.time.Instant.parse(CharSequence text) 方法。

package com.tutorialspoint;

import java.time.Instant;

public class InstantDemo {
   public static void main(String[] args) {

      Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");     
      System.out.println(instant);  
   }
}

讓我們編譯並執行上述程式,結果如下 -

2017-02-03T10:37:30Z
廣告
© . All rights reserved.