日期/时间格式/解析,Java 8样式

自Java 几乎 开始以来,Java开发人员就通过java.util.Date类(自JDK 1.0起)和java.util.Calendar类(自JDK 1.1起 )来处理日期和时间。 在这段时间内,成千上万(甚至可能数百万)的Java开发人员已使用java.text.DateFormat和java.text.SimpleDateFormat格式化并解析了Java日期和时间。 鉴于多年来这样做的频率,不足为奇的是,有很多关于这些类的日期和时间的解析和格式设置的 在线 示例和教程 。 经典的Java教程在“ 格式化”课程 ( Dates and Times )中介绍了这些java.util和java.text类。 Java教程中新的Date Time轨迹涵盖了Java 8中有关日期和时间的新类,以及它们的格式和解析 。 这篇文章提供了一些实际的例子。

在通过示例演示Java 8样式的日期/时间解析/格式化之前,先比较一下DateFormat / SimpleDateFormat和DateTimeFormatter的Javadoc描述。 下表包含可从Javadoc的比较中直接或间接搜集到的每种区分格式信息的区分信息。 从此表中可能最重要的观察结果是,新的DateTimeFormatter是线程安全的且不可变的,并且DateTimeFormatter提供了用于解析和格式化日期和时间的API的概述。

特性 DateFormat / SimpleDateFormat DateTimeFormatter
目的 “以与语言无关的方式格式化和解析日期或时间” “用于打印和解析日期时间对象的格式化程序。”
主要用于 java.util.Date
java.util.Calendar
java.time.LocalDate
java.time.LocalTime
java.time.LocalDateTime java.time.OffsetTime java.time.OffsetDateTime java.time.ZonedDateTime java.time.Instant
线程安全 “日期格式不同步。” “此类是不可变的并且是线程安全的。”
直接格式化 格式(日期) 格式(TemporalAccessor)
直接解析 parse(String) 解析(CharSequence,TemporalQuery)
间接格式化 无[除非您使用Groovy的Date.format(String)扩展名] LocalDate.format(DateTimeFormatter)
LocalTime.format(DateTimeFormatter)
LocalDateTime.format(DateTimeFormatter) OffsetTime.format(DateTimeFormatter) OffsetDateTime.format(DateTimeFormatter) ZonedDateTime.format(DateTimeFormatter)
间接解析 无[除非您使用不推荐使用的Date.parse(String)或Groovy的Date.parse(String,String)扩展名] LocalDate.parse(CharSequence,DateTimeFormatter)
LocalTime.parse(CharSequence,DateTimeFormatter)
LocalDateTime.parse(CharSequence,DateTimeFormatter) OffsetTime.parse(CharSequence,DateTimeFormatter) OffsetDateTime.parse(CharSequence,DateTimeFormatter) ZonedDateTime.parse(CharSequence,DateTimeFormatter)
国际化 java.util.Locale java.util.Locale
时区 java.util.TimeZone java.time.ZoneId
java.time.ZoneOffset
预定义格式器 没有,但是为常见实例提供了静态便利方法:
getDateInstance()
getDateInstance(int) getDateInstance(int,Locale) getDateTimeInstance() getDateTimeInstance(int,int) getDateTimeInstance(int,int,Locale) getInstance() getTimeInstance() getTimeInstance(int) getTimeInstance(int,Locale)
ISO_LOCAL_DATE
ISO_LOCAL_TIME
ISO_LOCAL_DATE_TIME ISO_OFFSET_DATE ISO_OFFSET_TIME ISO_OFFSET_DATE_TIME ISO_ZONED_DATE_TIME BASIC_ISO_DATE ISO_DATE ISO_DATE_TIME ISO_ORDINAL_DATE ISO_INSTANT ISO_WEEK_DATE RFC_1123_DATE_TIME

本文的其余部分将使用示例来演示如何使用java.time构造在Java 8中格式化和解析日期。 这些示例将使用以下字符串模式和实例。

/** Pattern to use for String representation of Dates/Times. */
private final String dateTimeFormatPattern = "yyyy/MM/dd HH:mm:ss z";/*** java.util.Date instance representing now that can* be formatted using SimpleDateFormat based on my* dateTimeFormatPattern field.*/
private final Date now = new Date();/*** java.time.ZonedDateTime instance representing now that can* be formatted using DateTimeFormatter based on my* dateTimeFormatPattern field.** Note that ZonedDateTime needed to be used in this example* instead of java.time.LocalDateTime or java.time.OffsetDateTime* because there is zone information in the format provided by* my dateTimeFormatPattern field and attempting to have* DateTimeFormatter.format(TemporalAccessor) instantiated* with a format pattern that includes time zone details* will lead to DateTimeException for instances of* TemporalAccessor that do not have time zone information* (such as LocalDateTime and OffsetDateTime).*/
private final ZonedDateTime now8 = ZonedDateTime.now();/*** String that can be used by both SimpleDateFormat and* DateTimeFormatter to parse respective date/time instances* from this String.*/
private final String dateTimeString = "2014/09/03 13:59:50 MDT";

在Java 8之前,用于日期和时间的标准Java方法是通过Date和Calendar类,而用于解析和格式化日期的标准方法是通过DateFormat和SimpleDateFormat 。 下一个代码清单演示了这些经典方法。

使用SimpleDateFormat格式化和解析Java日期

/*** Demonstrate presenting java.util.Date as String matching* provided pattern via use of SimpleDateFormat.*/
public void demonstrateSimpleDateFormatFormatting()
{final DateFormat format = new SimpleDateFormat(dateTimeFormatPattern);final String nowString = format.format(now);out.println("Date '" + now + "' formatted with SimpleDateFormat and '"+ dateTimeFormatPattern + "': " + nowString);
}/*** Demonstrate parsing a java.util.Date from a String* via SimpleDateFormat.*/
public void demonstrateSimpleDateFormatParsing()
{final DateFormat format = new SimpleDateFormat(dateTimeFormatPattern);try{final Date parsedDate = format.parse(dateTimeString);out.println("'" + dateTimeString + "' is parsed with SimpleDateFormat as " + parsedDate);}// DateFormat.parse(String) throws a checked exceptioncatch (ParseException parseException){out.println("ERROR: Unable to parse date/time String '"+ dateTimeString + "' with pattern '"+ dateTimeFormatPattern + "'.");}
}

在Java 8中,首选日期/时间类不再位于java.util包中,并且首选日期/时间处理类现在位于java.time包中。 类似地,首选的日期/时间格式/解析类不再位于java.text包中,而是来自java.time.format包。

java.time包提供了许多用于对日期和/或时间进行建模的类。 这些包括仅对日期建模(没有时间信息)的类,仅对时间建模(没有日期信息)的类,对日期和时间信息进行建模的类,使用时区信息的类以及不包含时区信息的类。 尽管类的特性(例如,是否支持日期或时间或时区信息)会影响可以应用的模式,但用于格式化和解析它们的方法通常是相似的。 在本文中,我将ZonedDateTime类用作示例。 选择该选项的原因是它包含日期,时间和时区信息,并允许我使用一个匹配模式,该模式涉及所有三个特征,例如Date或Calendar实例。 这样可以更轻松地比较新旧方法。

DateTimeFormatter类提供了ofPattern方法,用于基于所提供的日期/时间模式String提供DateTimeFormatter的实例。 然后可以在该DateTimeFormatter实例上调用一种格式方法,以获取日期和/或时间信息,格式为与提供的模式匹配的String。 下一个代码清单说明了基于提供的模式从ZonedDateTime格式化String这种方法。

将ZonedDateTime格式化为字符串

/*** Demonstrate presenting ZonedDateTime as a String matching* provided pattern via DateTimeFormatter and its* ofPattern(String) method.*/
public void demonstrateDateTimeFormatFormatting()
{final DateTimeFormatter formatter =DateTimeFormatter.ofPattern(dateTimeFormatPattern);final String nowString = formatter.format(now8);out.println(now8 + " formatted with DateTimeFormatter and '"+ dateTimeFormatPattern + "': " + nowString);
}

根据模式从字符串中解析日期/时间类很容易完成。 有两种方法可以实现。 一种方法是将DateTimeFormatter的实例传递给静态ZonedDateTime.parse(CharSequence,DateTimeFormatter)方法,该方法返回从提供的字符序列派生并基于提供的模式的ZonedDateTime实例。 下一个代码清单对此进行了说明。

使用静态ZonedDateTime.parse方法从字符串解析ZonedDateTime

/*** Demonstrate parsing ZonedDateTime from provided String* via ZonedDateTime's parse(String, DateTimeFormatter) method.*/
public void demonstrateDateTimeFormatParsingTemporalStaticMethod()
{final DateTimeFormatter formatter =DateTimeFormatter.ofPattern(dateTimeFormatPattern);final ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeString, formatter);out.println("'" + dateTimeString+ "' is parsed with DateTimeFormatter and ZonedDateTime.parse as "+ zonedDateTime);
}

从字符串解析ZonedDateTime第二种方法是通过DateTimeFormatter的parse(CharSequence,TemporalQuery <T>)方法。 在下面的代码清单中对此进行了说明,该清单也提供了演示Java 8 方法引用的用法的机会(请参见ZonedDateTime::from )。

使用DateTimeFormatter.parse方法从字符串解析ZonedDateTime

/*** Demonstrate parsing ZonedDateTime from String* via DateTimeFormatter.parse(String, TemporaryQuery)* with the Temple Query in this case being ZonedDateTime's* from(TemporalAccessor) used as a Java 8 method reference.*/
public void demonstrateDateTimeFormatParsingMethodReference()
{final DateTimeFormatter formatter =DateTimeFormatter.ofPattern(dateTimeFormatPattern);final ZonedDateTime zonedDateTime = formatter.parse(dateTimeString, ZonedDateTime::from);out.println("'" + dateTimeString+ "' is parsed with DateTimeFormatter and ZoneDateTime::from as "+ zonedDateTime);
}

很少有项目能成为可以从Java 8开始的未开发项目。因此,将JDK 8之前的日期/时间类与JDK 8中引入的新日期/时间类联系起来的类很有帮助。这方面的一个示例是JDK 8的DateTimeFormatter通过DateTimeFormatter.toFormat()方法提供JDK 8之前的抽象Format类的降序实例的功能。 下一个代码清单对此进行了演示。

从JDK 8的DateTimeFormatter访问JDK 8之前的格式

/*** Demonstrate formatting ZonedDateTime via DateTimeFormatter,* but using implementation of Format.*/
public void demonstrateDateTimeFormatAndFormatFormatting()
{final DateTimeFormatter formatter =DateTimeFormatter.ofPattern(dateTimeFormatPattern);final Format format = formatter.toFormat();final String nowString = format.format(now8);out.println("ZonedDateTime " + now + " formatted with DateTimeFormatter/Format (and "+ format.getClass().getCanonicalName() + ") and '"+ dateTimeFormatPattern + "': " + nowString);
}

该即时与两个前JDK 8工作时类是特别重要的DateCalendar结合类与JDK 8之所以引入新的日期和时间类Instant是如此重要的是, java.util.Date有方法从(即时)和toInstant()分别从Instant获取Date和从Date获取Instant 。 因为Instant在将Java 8之前的日期/时间处理迁移到Java 8基线非常重要,所以下一个代码清单演示了Instant实例的格式和解析。

格式化和解析Instant实例

/*** Demonstrate formatting and parsing an instance of Instant.*/
public void demonstrateDateTimeFormatFormattingAndParsingInstant()
{// Instant instances don't have timezone informationfinal Instant instant = now.toInstant();final DateTimeFormatter formatter =DateTimeFormatter.ofPattern(dateTimeFormatPattern).withZone(ZoneId.systemDefault());final String formattedInstance = formatter.format(instant);out.println("Instant " + instant + " formatted with DateTimeFormatter and '"+ dateTimeFormatPattern + "' to '" + formattedInstance + "'");final Instant instant2 =formatter.parse(formattedInstance, ZonedDateTime::from).toInstant();out.println(formattedInstance + " parsed back to " + instant2);
}

为了完整起见,所有上述示例均来自下一个代码清单中显示的示例类。

DateFormatDemo.java

package dustin.examples.numberformatdemo;import static java.lang.System.out;import java.text.DateFormat;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;/*** Demonstrates formatting dates as strings and parsing strings* into dates and times using pre-Java 8 (java.text.SimpleDateFormat)* and Java 8 (java.time.format.DateTimeFormatter) mechanisms.*/
public class DateFormatDemo
{/** Pattern to use for String representation of Dates/Times. */private final String dateTimeFormatPattern = "yyyy/MM/dd HH:mm:ss z";/*** java.util.Date instance representing now that can* be formatted using SimpleDateFormat based on my* dateTimeFormatPattern field.*/private final Date now = new Date();/*** java.time.ZonedDateTime instance representing now that can* be formatted using DateTimeFormatter based on my* dateTimeFormatPattern field.** Note that ZonedDateTime needed to be used in this example* instead of java.time.LocalDateTime or java.time.OffsetDateTime* because there is zone information in the format provided by* my dateTimeFormatPattern field and attempting to have* DateTimeFormatter.format(TemporalAccessor) instantiated* with a format pattern that includes time zone details* will lead to DateTimeException for instances of* TemporalAccessor that do not have time zone information* (such as LocalDateTime and OffsetDateTime).*/private final ZonedDateTime now8 = ZonedDateTime.now();/*** String that can be used by both SimpleDateFormat and* DateTimeFormatter to parse respective date/time instances* from this String.*/private final String dateTimeString = "2014/09/03 13:59:50 MDT";/*** Demonstrate presenting java.util.Date as String matching* provided pattern via use of SimpleDateFormat.*/public void demonstrateSimpleDateFormatFormatting(){final DateFormat format = new SimpleDateFormat(dateTimeFormatPattern);final String nowString = format.format(now);out.println("Date '" + now + "' formatted with SimpleDateFormat and '"+ dateTimeFormatPattern + "': " + nowString);}/*** Demonstrate parsing a java.util.Date from a String* via SimpleDateFormat.*/public void demonstrateSimpleDateFormatParsing(){final DateFormat format = new SimpleDateFormat(dateTimeFormatPattern);try{final Date parsedDate = format.parse(dateTimeString);out.println("'" + dateTimeString + "' is parsed with SimpleDateFormat as " + parsedDate);}// DateFormat.parse(String) throws a checked exceptioncatch (ParseException parseException){out.println("ERROR: Unable to parse date/time String '"+ dateTimeString + "' with pattern '"+ dateTimeFormatPattern + "'.");}}/*** Demonstrate presenting ZonedDateTime as a String matching* provided pattern via DateTimeFormatter and its* ofPattern(String) method.*/public void demonstrateDateTimeFormatFormatting(){final DateTimeFormatter formatter =DateTimeFormatter.ofPattern(dateTimeFormatPattern);final String nowString = formatter.format(now8);out.println(now8 + " formatted with DateTimeFormatter and '"+ dateTimeFormatPattern + "': " + nowString);}/*** Demonstrate parsing ZonedDateTime from provided String* via ZonedDateTime's parse(String, DateTimeFormatter) method.*/public void demonstrateDateTimeFormatParsingTemporalStaticMethod(){final DateTimeFormatter formatter =DateTimeFormatter.ofPattern(dateTimeFormatPattern);final ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeString, formatter);out.println("'" + dateTimeString+ "' is parsed with DateTimeFormatter and ZonedDateTime.parse as "+ zonedDateTime);}/*** Demonstrate parsing ZonedDateTime from String* via DateTimeFormatter.parse(String, TemporaryQuery)* with the Temple Query in this case being ZonedDateTime's* from(TemporalAccessor) used as a Java 8 method reference.*/public void demonstrateDateTimeFormatParsingMethodReference(){final DateTimeFormatter formatter =DateTimeFormatter.ofPattern(dateTimeFormatPattern);final ZonedDateTime zonedDateTime = formatter.parse(dateTimeString, ZonedDateTime::from);out.println("'" + dateTimeString+ "' is parsed with DateTimeFormatter and ZoneDateTime::from as "+ zonedDateTime);}/*** Demonstrate formatting ZonedDateTime via DateTimeFormatter,* but using implementation of Format.*/public void demonstrateDateTimeFormatAndFormatFormatting(){final DateTimeFormatter formatter =DateTimeFormatter.ofPattern(dateTimeFormatPattern);final Format format = formatter.toFormat();final String nowString = format.format(now8);out.println("ZonedDateTime " + now + " formatted with DateTimeFormatter/Format (and "+ format.getClass().getCanonicalName() + ") and '"+ dateTimeFormatPattern + "': " + nowString);}/*** Demonstrate formatting and parsing an instance of Instant.*/public void demonstrateDateTimeFormatFormattingAndParsingInstant(){// Instant instances don't have timezone informationfinal Instant instant = now.toInstant();final DateTimeFormatter formatter =DateTimeFormatter.ofPattern(dateTimeFormatPattern).withZone(ZoneId.systemDefault());final String formattedInstance = formatter.format(instant);out.println("Instant " + instant + " formatted with DateTimeFormatter and '"+ dateTimeFormatPattern + "' to '" + formattedInstance + "'");final Instant instant2 =formatter.parse(formattedInstance, ZonedDateTime::from).toInstant();out.println(formattedInstance + " parsed back to " + instant2);}/*** Demonstrate java.text.SimpleDateFormat and* java.time.format.DateTimeFormatter.** @param arguments Command-line arguments; none anticipated.*/public static void main(final String[] arguments){final DateFormatDemo demo = new DateFormatDemo();out.print("\n1: ");demo.demonstrateSimpleDateFormatFormatting();out.print("\n2: ");demo.demonstrateSimpleDateFormatParsing();out.print("\n3: ");demo.demonstrateDateTimeFormatFormatting();out.print("\n4: ");demo.demonstrateDateTimeFormatParsingTemporalStaticMethod();out.print("\n5: ");demo.demonstrateDateTimeFormatParsingMethodReference();out.print("\n6: ");demo.demonstrateDateTimeFormatAndFormatFormatting();out.print("\n7: ");demo.demonstrateDateTimeFormatFormattingAndParsingInstant();}
}

下一个屏幕快照中显示了运行上述演示的输出。

jdk8DateTimeFormattingDemonstrationOutput

结论

与JDK 8之前的版本相比,JDK 8日期/时间类以及相关的格式和解析类更易于使用。 这篇文章试图演示如何应用这些新类并利用它们的某些优点。

翻译自: https://www.javacodegeeks.com/2014/09/datetime-formattingparsing-java-8-style.html

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

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

相关文章

vue-router 响应路由参数的变化

提醒一下&#xff0c;当使用路由参数时&#xff0c;例如从 /user/foo 导航到 /user/bar&#xff0c;原来的组件实例会被复用。因为两个路由都渲染同个组件&#xff0c;比起销毁再创建&#xff0c;复用则显得更加高效。不过&#xff0c; 这也意味着组件的生命周期钩子不会再被…

无废话WPF系列5:控件派生图

1. WPF类控件的派生关系图&#xff0c;紫色的部分开始才算是进入WPF的框架里。 2. WPF控件图 WPF的UI控件主要有以下类型&#xff0c;ContentControl, HeaderedContentControl, ItemsControl, HeaderedItemsControl, Panel, Adorner(文字点缀元素), Flow Text(流式文本元素), T…

安装ipython和jupyter

本节内容&#xff1b; 安装ipython安装jupyterPycharm介绍 Python软件包管理一、安装ipython 1. python的交互式环境2. 安装ipython 可以使用pip命令安装。如果你是用pyenv安装的python的话&#xff0c;pip命令已经有了。 当需要安装包的时候&#xff0c;最好进入虚拟环境&…

vue 图片资源应该如何存放并引入(public、assets)?

全局cli配置&#xff1a;vue.config.js 之前写项目就想着怎么简单怎么来&#xff0c;图片要用了&#xff0c;就直接在要用图片的页面&#xff0c;新建一个跟页面同等级的 imgs 文件夹&#xff0c;然后在页面中直接 “./imgs/图片.png”&#xff0c;不得不说这样写很方便。 但是…

真正的动态声明性组件

在这篇简短的文章中&#xff0c;我将重点介绍ADF动态声明性组件。 我的意思是一个众所周知的ADF标签af&#xff1a;declarativeComponent 。 它可以用作将页面设计为页面片段和组件组成的一种非常便捷的方法。 例如&#xff0c;我们的页面可以包含以下代码片段&#xff1a; &l…

layui 树形组件下拉框

采用 layui 树形组件&#xff0c;版本&#xff1a;V2.6.8。只需要更新layui版本&#xff0c;不需要下载tableSelect。 原作者博客&#xff1a;https://blog.csdn.net/m0_67402588/article/details/123526860。 从 官网 更新日志可以看到&#xff0c;树形组件在2.5.7版本还在更新…

访问修饰符(C# 编程指南)

所有类型和类型成员都具有可访问性级别&#xff0c;用来控制是否可以在您程序集的其他代码中或其他程序集中使用它们。您在声明类型或成员时使用以下访问修饰符之一来指定其可访问性&#xff1a; public 同一程序集中的任何其他代码或引用该程序集的其他程序集都可以访问该类型…

vuex Payload 荷载

1、payload payload&#xff1a;有效载荷&#xff0c;即记录有效信息的部分。 通常在传输数据时&#xff0c;为了使数据传输更可靠&#xff0c;要把原始数据分批传输&#xff0c;并且在每一批数据的头和尾都加上一定的辅助信息&#xff0c;比如这一批数据量的大小&#xff0c…

JSP知识总结

day11 JSP入门 1 JSP概述 1.1 什么是JSP JSP&#xff08;Java Server Pages&#xff09;是JavaWeb服务器端的动态资源。它与html页面的作用是相同的&#xff0c;显示数据和获取数据。 1.2 JSP的组成 JSP html Java脚本&#xff08;代码片段&#xff09; JSP动态标签 2 J…

layui table表格的复选框checkbox设置部分为不可选

需求&#xff1a;如上图&#xff0c;某些数据禁用删除功能&#xff0c;那么全选时&#xff0c;这些数据前面的复选框也不能选。 实现&#xff1a;在layui数据表格中设置了字段为 type:checkbox 但是想要实现部分不显示&#xff0c;不可选的功能。layui内置没有该功能&#xff…

Katas编写的Java教程:Mars Rover

编程kata是一种练习&#xff0c;可以帮助程序员通过练习和重复练习来磨练自己的技能。 本文是“ 通过Katas进行Java教程 ”系列的一部分。 本文假定读者已经具有Java的经验&#xff0c;熟悉单元测试的基础知识&#xff0c;并且知道如何从他最喜欢的IDE&#xff08;我是Intell…

es6 includes(), startsWith(), endsWith()

传统上&#xff0c;JavaScript 只有 indexOf方法&#xff0c;可以用来确定一个字符串是否包含在另一个字符串中。ES6 又提供了三种新方法。includes()&#xff1a;返回布尔值&#xff0c;表示是否找到了参数字符串。startsWith()&#xff1a;返回布尔值&#xff0c;表示参数字符…

Rails之格式化价格方法

一种是直接在试图中队价格信息进行格式化如&#xff1a;<div class"price"><%sprintf("&#xffe5;%0.02f",product.price)%></div>另外一种是用单独的辅助方法来处理价格格式化&#xff0c;即number_to_currency&#xff0c;如&#x…

CodeCombat代码全记录(Python学习利器)--Kithgard地牢代码1

Kithgard地牢注意&#xff1a;在调用函数时&#xff0c;要在函数的后面加上括号内容&#xff0c;否则在python中&#xff0c;将不会认为你在调用这个函数内容&#xff0c;而你的英雄将像木头一样站在原地不会执行上左下右的移动&#xff01;&#xff01;&#xff01; hero.move…

layui upload阻止文件上传问题,及多选文件上传

1、效果展示&#xff1a; 2、需求&#xff1a; 下拉框及月份都为不空&#xff0c;且有文件数据才能提交上传。 3、环境&#xff1a; 目前项目中引用的 layui 版本是 2.4.5。在 before 中进行判断&#xff0c;使用 return false 想要阻止文件上传没反应&#xff0c;文件仍然会…

JPA教程:实体映射-第2部分

在上一篇文章中&#xff0c;我展示了一种持久保存实体的简单方法。 我解释了JPA用于确定实体默认表的默认方法。 假设我们要覆盖此默认名称。 我们之所以喜欢这样做&#xff0c;是因为数据模型是以前设计和修复的&#xff0c;并且表名与我们的类名不匹配&#xff08;例如&#…

Vue DOM事件

本文参考自&#xff1a;https://mp.weixin.qq.com/s?src3&timestamp1527154113&ver1&signaturetWGeTa86gyK*RL0P7nwlA6-8V14FjzxUTh7CM9kQLjl0DV3sx*2hKauMGZKoYBkTSp14Zw6MOD8pU-haYmJoNTSBI5rptCZwf3wTIXLUMUOYDOPZtxm9wJaSm0l7vqshH98ToXQCcfm-5jR-Y66eAYzuFM5…

2019.06.17课件:[洛谷P1310]表达式的值 题解

P1310 表达式的值 题目描述 给你一个带括号的布尔表达式&#xff0c;其中表示或操作|&#xff0c;*表示与操作&&#xff0c;先算*再算。但是待操作的数字&#xff08;布尔值&#xff09;不输入。 求能使最终整个式子的值为0的方案数。 题外话 不久之前我在codewars上做过一…

vue+element 封装日期范围组件(双向绑定)

像这样的日期组件&#xff0c;在后台管理项目中是比较多的&#xff0c;而且加了快捷选项&#xff0c;代码量较多&#xff0c;因此封装成组件。 封装这一类型的组组件&#xff0c;主要是了解输入框双向绑定 v-model 的过程。 1、了解输入框双向绑定的过程&#xff1a; 官网&am…

句柄是什么?1

句柄是什么&#xff1f; 1.句柄是什么&#xff1f; 在windows中&#xff0c;句柄是和对象一一对应的32位无符号整数值。对象可以映射到唯一的句柄&#xff0c;句柄也可以映射到唯一的对象。2.为什么我们需要句柄&#xff1f; 更准确地说&#xff0c;是windows需要句柄。w…