java.time.LocalDate parse()方法

java.time.LocalDate.parse(CharSequence text,DateTimeFormatter formatter)方法使用特定格式化程序从文本字符串中获取LocalDate的实例。

1 语法

public static LocalDate parse(CharSequence text, DateTimeFormatter formatter)

2 参数

text:要解析的文本,例如:2017-02-03,而不是null。

formatter:要使用的格式化程序,而不是null。

3 返回值

本地日期,不为null。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.time.LocalDate parse()方法
 */
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class LocalDateDemo {
   public static void main(String[] args) {

       DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd MMM uuuu");
       String date = "03 Feb 2017";
       LocalDate localDate = LocalDate.parse(date, dateTimeFormatter);
       System.out.println(localDate);
   }
}

输出结果为:

2017-02-03

 

热门文章

优秀文章