LocalDate类format()方法 (LocalDate Class format() method)

  • format() method is available in java.time package.

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

  • format() method is used to format this LocalDate object by using the given DateTimeFormatter object.

    format()方法用于通过使用给定的DateTimeFormatter对象来格式化此LocalDate对象。

  • format() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    format()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • format() method may throw an exception at the time of formatting this object.

    在格式化此对象时, format()方法可能会引发异常。

    DateTimeException: This exception may throw when getting any error during formatting.

    DateTimeException :格式化期间发生任何错误时,可能会引发此异常。

Syntax:

句法:

    public String format(DateTimeFormatter dt_formatter);

Parameter(s):

参数:

  • DateTimeFormatter dt_formatter – represents the formatter to format this object.

    DateTimeFormatter dt_formatter –表示用于格式化此对象的格式化程序。

Return value:

返回值:

The return type of this method is String, it returns date formatted by the given formatter of this LocalDate object.

此方法的返回类型为String ,它返回由此LocalDate对象的给定格式化程序格式化的日期。

Example:

例:

// Java program to demonstrate the example
// of format(DateTimeFormatter dt_formatter)
// method of LocalDate
import java.time.*;
import java.time.format.*;
public class FormatOfLocalDate {public static void main(String args[]) {// Instantiates two LocalDate
LocalDate l_da1 = LocalDate.parse("2007-04-04");
LocalDate l_da2 = LocalDate.now();
// Display l_da1,l_da2
System.out.println("LocalDate l_da1 and l_da2: ");
System.out.println("l_da1: " + l_da1);
System.out.println("l_da2: " + l_da2);
System.out.println();
// Here, this method formats this date
// by using the pattern "dd-MMM-yyyy"
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy");
String format = l_da1.format(dtf);
// Display format
System.out.println("l_da1.format(dtf): " + format);
// Here, this method formats this date by
// using the pattern "dd/MM/yyyy"
dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy");
format = l_da2.format(dtf);
// Display format
System.out.println("l_da2.format(dtf): " + format);
}
}

Output

输出量

LocalDate l_da1 and l_da2:
l_da1: 2007-04-04
l_da2: 2020-05-29l_da1.format(dtf): 04-Apr-2007
l_da2.format(dtf): 29/05/2020

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

Java LocalDate类| 带示例的format()方法相关推荐

  1. Java LocalDate类| 带示例的getDayOfYear()方法

    LocalDate类的getDayOfYear()方法 (LocalDate Class getDayOfYear() method) getDayOfYear() method is availab ...

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

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

  3. Java LocalDate类| 带示例的getEra()方法

    LocalDate类的getEra()方法 (LocalDate Class getEra() method) getEra() method is available in java.time pa ...

  4. Java BigInteger类| 带示例的shiftLeft()方法

    BigInteger类shiftLeft()方法 (BigInteger Class shiftLeft() method) shiftLeft() method is available in ja ...

  5. Java LocalDateTime类| 带示例的getDayOfWeek()方法

    LocalDateTime类getDayOfWeek()方法 (LocalDateTime Class getDayOfWeek() method) getDayOfWeek() method is ...

  6. Java Duration类| 带示例的compareTo()方法

    持续时间类compareTo()方法 (Duration Class compareTo() method) compareTo() method is available in java.time ...

  7. Java LocalDateTime类| 带示例的getMinute()方法

    LocalDateTime类getMinute()方法 (LocalDateTime Class getMinute() method) getMinute() method is available ...

  8. Java即时类| 带示例的compareTo()方法

    即时类compareTo()方法 (Instant Class compareTo() method) compareTo() method is available in java.time pac ...

  9. Java LocalDateTime类| 带示例的compareTo()方法

    LocalDateTime类compareTo()方法 (LocalDateTime Class compareTo() method) compareTo() method is available ...

最新文章

  1. “掘金”金融AI落地,英特尔趟出一套通关攻略
  2. 2021年机器学习什么风向?谷歌大神Quoc Le:把注意力放在MLP上
  3. kettle中过滤记录中时间_Kettle中Step:Text file outpout功能
  4. fiddler打开后 浏览器就上不了网的解决方法
  5. int在c语言中的作用,C语言中int,Uint,uint16等有什么区别以及用处
  6. 简单批处理内部命令简介(转)
  7. oracle 11g dataguard创建的简单方法
  8. 数据的提取方法 - 1
  9. 最齐全的骨头VRay材质球素材,速来收藏
  10. 苹果隐私十年史:变与不变(3)产品与常识
  11. Win10常用Win快捷键
  12. 单选题计算机科学的奠基人是,超星尔雅计算机课程(2017年)
  13. The type of the expression must be an array type but it resolved to ListObj
  14. 斯坦福大学公开课 :机器学习课程笔记-[第1集] 机器学习的动机与应用
  15. 前端 flex: 1; 到底是什么意思?
  16. 昨天与友人聊的二三观点
  17. python 获取各pkg版本_Python pkg_resources.get_distribution方法代碼示例
  18. 腾讯TEG一面(电话面试)
  19. 股票入门(一)基础知识
  20. 怎样利用python写游戏辅助_怎样才能写游戏辅助?

热门文章

  1. 传统的6d位姿估计fangfa1_李飞飞团队最新论文:基于anchor关键点的类别级物体6D位姿跟踪...
  2. Linux fast open,Linux内核3.7 TCP Fast Open验证实例
  3. 就业技术书文件表格_公路工程全套资料—开工施工检验等表格范本,及监理内业常用资料...
  4. 跨域产生的原因和解决方法_板式家具开料机加工过程产生崩边原因及解决方法...
  5. 【bfs】调酒壶里的酸奶
  6. 清北学堂培训2019.4.4
  7. vue服务端渲染添加缓存
  8. Facebook产品经理的三年叙事与协作思考
  9. HDU 4923 Room and Moor(瞎搞题)
  10. 上手Caffe(一)