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



描述

java.time.LocalDateTime.toString() 方法將此日期輸出為一個字串,例如 2017-12-03T10:15:30。

宣告

以下是 java.time.LocalDateTime.toString() 方法的宣告。

public String toString()

返回值

此日期的字串表示形式,非空。

示例

以下示例展示了 java.time.LocalDateTime.toString() 方法的用法。

package com.tutorialspoint;

import java.time.LocalDateTime;

public class LocalDateTimeDemo {
   public static void main(String[] args) {
 
      LocalDateTime date = LocalDateTime.now();
      System.out.println(date.toString());  
   }
}

讓我們編譯並執行上述程式,它將產生以下結果 −

2017-03-17T16:38:55.942
廣告
© . All rights reserved.