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 LocalDate
import 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
// CharSequence
LocalDate l_da = LocalDate.parse(c_seq);
// Display l_da
System.out.println("LocalDate.parse(c_seq): " + l_da);
// Here, parse(CharSequence,DateTimeFormatter)
// creates an instance of LocalDate from a
// CharSequence by using the given
// DateTimeFormatter
l_da = LocalDate.parse("15-Aug-1991", dtf);
// Display l_da
System.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()方法与示例相关推荐

  1. java annotation class,Java Class类 isAnnotation()方法及示例

    Class类isAnnotation()方法isAnnotation()方法在java.lang包中可用. isAnnotation()方法用于检查此Class对象是否表示注释类型. isAnnota ...

  2. java字符类型的返回值,Java字符类isWhitespace()方法及示例

    Character 类isWhitespace()法isWhitespace()方法在java.lang包中可用. isWhitespace()方法用于检查给定的char值是否为空格,但是它包含空格中 ...

  3. Java LocalDate类| minusYears()方法与示例

    LocalDate类minusYears()方法 (LocalDate Class minusYears() method) minusYears() method is available in j ...

  4. Java LocalDate类| minus()方法与示例

    LocalDate类isSupported()方法 (LocalDate Class isSupported() method) Syntax: 句法: public LocalDate minus( ...

  5. Java LocalDate类| 带示例的format()方法

    LocalDate类format()方法 (LocalDate Class format() method) format() method is available in java.time pac ...

  6. Java LocalDate类| toString()方法与示例

    LocalDate类toString()方法 (LocalDate Class toString() method) toString() method is available in java.ti ...

  7. Java LocalDate类| 带示例的compareTo()方法

    LocalDate类compareTo()方法 (LocalDate Class compareTo() method) compareTo() method is available in java ...

  8. Java LocalDate类| minusWeeks()方法与示例

    LocalDate类minusWeeks()方法 (LocalDate Class minusWeeks() method) minusWeeks() method is available in j ...

  9. Java LocalDate类| isSupported()方法与示例

    LocalDate类isSupported()方法 (LocalDate Class isSupported() method) Syntax: 句法: public boolean isSuppor ...

最新文章

  1. Spring.net使用说明
  2. ERNIE-GeoL:“地理位置-语言”预训练模型
  3. 汇总Web前端开发工程师需要注意的一些开发规范
  4. 让0球平局怎么算_半场16中5+0助攻+空气球,欧文威化,看看众美媒怎么说?
  5. URL处理两个小工具方法
  6. c语言语法格式规范(1)常量的非法与合法
  7. 小米开源移动端深度学习框架MACE,自主研发,专为IoT设备优化
  8. python numpy数据类型_Python中numpy的数据类型,python,dtype
  9. 信息与安全工程学院2013-2014学年“五四”表彰获奖公示
  10. led灯闪烁代码_如何设置LED灯并使其通过代码闪烁
  11. WEEX UI 官网
  12. SQL 身份证获取性别
  13. python 过滤相似图片_Python过滤纯色图片,挑选视频封面
  14. linux mips 时钟中断,Linux内核中地时钟中断.pdf
  15. (夏季)你不得不注意的一种比蚊子还可怕的东西!
  16. 怎样知道别人的WiFi密码?
  17. 震惊!点几下鼠标就能看到这个网站是不是用凡科搭建的?!
  18. 年底了,如何高效的与领导提加薪?
  19. HTML自动暂停按钮,css播放暂停按钮实现_html/css_WEB-ITnose
  20. 自己动手打造PE系统

热门文章

  1. 'mysql_attr_use_buffered_query'_php中mysql操作的buffer知识
  2. Three.js制作360度全景图
  3. tooltip.css-2.0文档
  4. Jquery 日历控件
  5. MySql - GROUP BY 和 HAVING关键字
  6. cocos2dx 3.x 蒙板 遮罩 点击圆功能
  7. 拓扑排序最长链-P3119 [USACO15JAN]草鉴定Grass Cownoisseur
  8. 数据库行转列在现实需求中的用法
  9. Spring之HibernateTemplate 和HibernateDaoSupport
  10. 转:只能选择GridView中的一个CheckBox(单选CheckBox)