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

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541554.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

胃癌2019csco指南_2019 CSCO胃癌诊疗指南精华来了!

一文轻松get 2019 CSCO胃癌诊疗指南更新要点!文丨青青子衿 中山大学肿瘤防治中心来源丨医学界肿瘤频道近日,2019年CSCO指南发布会于南京召开。今天为大家推送的是2019 CSCO胃癌诊疗指南的最新更新,在发布专场中,来自华中科技大学同…

001_docker-compose构建elk环境

由于打算给同事分享elk相关的东西,搭建配置elk环境太麻烦了,于是想到了docker。docker官方提供了docker-compose编排工具,elk集群一键就可以搞定,真是兴奋。好了下面咱们开始吧。 一、 https://github.com/deviantony/docker-elk $ cd /006_xxxallproject/005_docker/001_e…

Java即时类| toString()方法与示例

即时类toString()方法 (Instant Class toString() method) toString() method is available in java.time package. toString()方法在java.time包中可用。 toString() method is used to represent this Instant as a String by using the standards ISO-8601 format. toString…

learn opengl 中文_LearnOpenGL CN

欢迎来到OpenGL的世界欢迎来到OpenGL的世界。这个工程只是我(Joey de Vries)的一次小小的尝试,希望能够建立起一个完善的OpenGL教学平台。无论你学习OpenGL是为了学业,找工作,或仅仅是因为兴趣,这个网站都将能够教会你现代(Core-p…

MYSQL5.7 日志管理

2019独角兽企业重金招聘Python工程师标准>>> 慢查询日志slow-query-log1 slow-query-log-filefile_name long_query_time1 #SQL执行多长时间以上会记录到慢查询日志,0~10s log_slow_admin_statementsOFF #在写入慢查询日志的语句中包含缓慢的管理语句。 …

duration java_Java Duration类| ofHours()方法与示例

duration javaDuration Class of Hours()方法 (Duration Class ofHours() method) ofHours() method is available in java.time package. ofHours()方法在java.time包中可用。 ofHours() method is used to represent the given hours in this Duration. ofHours()方法用于表示…

sumo的简单应用_sumo快速运行简单仿真实例详细教程

本文旨在让大家快速的了解sumo,并给出运行一个简单的sumo的例子的教程,进而了解基本sumo工程的架构,使大家对该软件产生兴趣并持续学习下去,刚开始学习仿真的确枯燥,项目“跑起来”才是大家学习下去的动力,…

stl vector 函数_vector :: crbegin()函数,以及C ++ STL中的示例

stl vector 函数C vector :: crbegin()函数 (C vector::crbegin() function) vector::crbegin() is a library function of "vector" header, it is used to get the last element of a vector using const_reverse_iterator, it returns a const reverse iterator …

ReactNative学习笔记(二)Flex布局

flexDirection 决定主轴方向 column:垂直方向为主轴row:水平方向为主轴justifyContent 决定主轴元素排列方式 flex-startflex-endcenterspace-betweenspace-aroundalignItems 决定侧轴元素排列方向 flex-startflex-endcenterbaselinestretch

cad导出 dxf后中文不显示_CAD快速看图 for Mac

CAD快速看图 for Mac是一款非常小巧、快速、方便的DWG看图工具,CAD快速看图 Mac版可脱离AutoCAD最快速、最方便浏览DWG和DXF图纸,支持二维或三维图纸,支持高清、多文件和云字体,非常实用的一款CAD看图软件,CAD快速看图…

scala运算符_Scala的所有符号运算符是什么意思?

scala运算符Scala的符号运算符 (Scalas symbolic operators) The symbolic operators in Scala are symbols that have a specific task that they perform when called in a Scala program. Scala library defines a lot of symbols that can be used while programming in Sc…

关于java.util.ConcurrentModificationException和remove倒数第二个元素

2019独角兽企业重金招聘Python工程师标准>>> 首先是两段代码的执行结果&#xff1a; 代码一&#xff1a; public class TestListRemove {public static void main(String[] args) {List<Integer> list new ArrayList<Integer>();list.add(1);list.add(…

linux 操作mysql 数据库命令_Linux 操作数据库命令

一、连接数据库格式&#xff1a; mysql -h主机地址 -u用户名 &#xff0d;p用户密码mysql -hlocalhost -uroot -p123注&#xff1a;-h,-u,-p 后面不加空格&#xff0c;进入数据库操作后每个命令结尾都需加“&#xff1b;(分号)”二、退出MYSQL命令exit (回车)三、显示所有数据库…

fragment和Activity同时操作UI引起的延迟、卡顿

最近项目中遇到一个问题&#xff0c;app首页的Activity中由若干个Fragment页面组成&#xff0c;其中一个fragment页面是由一个GridView和ListView组成的列表&#xff0c;如果列表中数据量过大的时候&#xff0c;在请求数据的时候点击页面上的其他按钮会无响应&#xff0c;直到该…

怎么删除mysql的压缩包_压缩包版mysql怎么卸载

MySQL是一个小巧玲珑但功能强大的数据库&#xff0c;目前十分流行。但是官网给出的安装包有两种格式&#xff0c;一个是msi格式&#xff0c;一个是zip格式的。那么压缩版mysql要怎么卸载&#xff1f;下面本篇文章就来大家介绍一下&#xff0c;希望对你们有所帮助。卸载压缩包版…

obj.val 非数组_在Ruby中使用Array.new(size,obj)创建数组

obj.val 非数组In the previous article, we have learnt how we can declare an Array class instance with the help of Array.[](*args) method? You can also notice that in the program codes written to demonstrate all those methods are having Array instances dec…

julia在mac环境变量_在Julia中找到值/变量的类型

julia在mac环境变量To find the type of a variable/value, we use the typeof() function – it accepts a parameter whose type to be found and returns its data type. 为了找到变量/值的类型&#xff0c;我们使用typeof()函数-它接受要查找其类型的参数并返回其数据类型。…

lambda表达式之进化

前言在C#我们可以自定义委托&#xff0c;但是C#为什么还要内置泛型委托呢&#xff1f;因为我们常常要使用委托&#xff0c;如果系统内置了一些你可能会用到的委托&#xff0c;那么就省去了定义委托&#xff0c;然后实例化委托的步骤&#xff0c;这样一来既使代码看起来简洁而干…

mysql返回行数_如何计算MySQL查询返回的行数?

How can I count the number of rows that a MySQL query returned?解决方案Getting total rows in a query result...You could just iterate the result and count them. You dont say what language or client library you are using, but the API does provide a mysql_nu…

md5不是对称密码算法_密码学中的消息摘要算法5(MD5)

md5不是对称密码算法In cryptography, MD5 (Message-Digest algorithm 5) is a mainly used cryptographic hash function with a 128-bit hash value. As we use in an Internet standard (RFC 1321), MD5 has been employed or developed in a more variety of security appl…