博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java LocalDate类| parse()方法与示例
阅读量:2529 次
发布时间:2019-05-11

本文共 2903 字,大约阅读时间需要 9 分钟。

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 // 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-05LocalDate.parse(15-Aug-1991,dtf): 1991-08-15

翻译自:

转载地址:http://grxzd.baihongyu.com/

你可能感兴趣的文章
HTML学习笔记
查看>>
selinux详解及配置文件
查看>>
性能优化之数据库优化
查看>>
Swift - 继承UIView实现自定义可视化组件(附记分牌样例)
查看>>
android自定义viewgroup实现等分格子布局
查看>>
springboot 配置mybatis
查看>>
10慕课网《进击Node.js基础(一)》初识promise
查看>>
JavaScript事件
查看>>
mysql 命令之工作小结
查看>>
linux 系统下 tar 的压缩与解压缩命令
查看>>
阿里负载均衡,配置中间证书问题(在starcom申请免费DV ssl)
查看>>
转:How to force a wordbreaker to be used in Sharepoint Search
查看>>
MySQL存储过程定时任务
查看>>
UVa 1658,Admiral (拆点+限制最小费用流)
查看>>
Python中and(逻辑与)计算法则
查看>>
POJ 3267 The Cow Lexicon(动态规划)
查看>>
设计原理+设计模式
查看>>
音视频处理
查看>>
Careercup - Facebook面试题 - 5890898499993600
查看>>
浮点数在内存中的存储方式
查看>>