日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java LocalDate类| parse()方法与示例

發布時間:2023/12/1 java 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java LocalDate类| parse()方法与示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

LocalDate類parse()方法 (LocalDate Class parse() method)

Syntax:

句法:

public static LocalDate parse(CharSequence c_seq); public static LocalDate parse(CharSequence c_seq, DateTimeFormatter fmtr);
  • parse() method is available in java.time package.

    parse()方法在java.time包中可用。

  • parse(CharSequence c_seq) method is used to create an instance of LocalDate from parsing the given char sequence.

    parse(CharSequence c_seq)方法用于通過解析給定的char序列來創建LocalDate的實例。

  • parse(CharSequence c_seq, DateTimeFormatter fmtr) method is used to create an instance of LocalDate from parsing the given char sequence based on the given formatter.

    parse(CharSequence c_seq,DateTimeFormatter fmtr)方法用于根據給定的格式器解析給定的char序列來創建LocalDate的實例。

  • These methods may throw an exception at the time of the represent date.

    這些方法在表示日期時可能會引發異常。

    DateTimeParseException: This exception may throw when the given parameter can't parse.

    DateTimeParseException:當給定參數無法解析時,可能引發此異常。

  • These are static methods and it is accessible with the class name and if we try to access these methods with the class object then we will not get an error.

    這些是靜態方法,可通過類名進行訪問,如果嘗試使用類對象訪問這些方法,則不會出錯。

Parameter(s):

參數:

  • In the first cases, parse(CharSequence c_seq),

    在第一種情況下,parse(CharSequence c_seq)

    • CharSequence c_seq – represents the sequence to parse in this object.
    • CharSequence c_seq –表示要在此對象中解析的序列。
  • In the second cases, parse(CharSequence c_seq, DateTimeFormatter fmtr),

    在第二種情況下,解析(CharSequence c_seq,DateTimeFormatter fmtr),

    • CharSequence c_seq – Similar as defined in the first case.
    • CharSequence c_seq –與第一種情況下定義的相似。
    • DateTimeFormatter fmtr – represents the formatter to format the sequence in this object.
    • DateTimeFormatter fmtr –表示格式化程序,用于格式化此對象中的序列。

Return value:

返回值:

In both the cases, the return type of the method is LocalDate, it returns the date that holds the value parsed the given sequence in a formatted manner.

在這兩種情況下,方法的返回類型均為LocalDate ,它以格式化的方式返回保存解析給定序列的值的日期。

Example:

例:

// Java program to demonstrate the example // of parse() method of LocalDateimport java.time.*; import java.time.format.*;public class ParseOfLocalDate {public static void main(String args[]) {CharSequence c_seq = "2005-06-05";DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy");// Here, parse(CharSequence) create an// instance of LocalDate from a// CharSequenceLocalDate l_da = LocalDate.parse(c_seq);// Display l_daSystem.out.println("LocalDate.parse(c_seq): " + l_da);// Here, parse(CharSequence,DateTimeFormatter)// creates an instance of LocalDate from a // CharSequence by using the given// DateTimeFormatterl_da = LocalDate.parse("15-Aug-1991", dtf);// Display l_daSystem.out.println("LocalDate.parse(15-Aug-1991,dtf): " + l_da.toString());} }

Output

輸出量

LocalDate.parse(c_seq): 2005-06-05 LocalDate.parse(15-Aug-1991,dtf): 1991-08-15

翻譯自: https://www.includehelp.com/java/localdate-parse-method-with-example.aspx

總結

以上是生活随笔為你收集整理的Java LocalDate类| parse()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。