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



說明

java.time.LocalDateTime.parse(CharSequence text) 方法使用文字字串(如 2017-02-03T10:15:30)獲取 LocalDateTime 例項。

宣告

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

public static LocalDateTime parse(CharSequence text)

引數

text - 要解析的文字,如“2017-02-03T10:15:30”,非空。

返回值

LocalDateTime,非空。

異常

DateTimeParseException - 如果無法解析文字。

示例

以下示例演示了 java.time.LocalDateTime.parse(CharSequence text) 方法的使用。

package com.tutorialspoint;

import java.time.LocalDateTime;

public class LocalDateTimeDemo {
   public static void main(String[] args) {
 
      LocalDateTime date = LocalDateTime.parse("2017-02-03T10:15:30");
      System.out.println(date);  
   }
}

編譯並執行以上程式後,結果如下所示:

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