Java数据类型仅保留日期 [英] Java data type to hold only date
问题描述
Java中哪种数据类型可以仅保存日期,并且不需要时间成分?例如,仅存储 2012年12月7日
.我正在与具有仅日期数据类型的数据库进行数据持久化,因此我正在寻找Java中最佳的等效数据类型.
Which data type in Java can hold just the date and doesn't require a time component? For example, just to store 12/07/2012
. I'm working with persisting the data to/from a database that has a date-only data type, so I'm looking for the best equivalent data type in Java.
推荐答案
: 一个毫秒值左右的精简包装器,它使JDBC能够识别这是一个SQL DATE值.毫秒值代表数字自 要符合SQL DATE的定义,毫秒值由 To conform with the definition of SQL DATE, the millisecond values
wrapped by a 或来自 JodaTime : or from JodaTime: 重要的是要强调,该课程代表了在任何一天的午夜.请注意,午夜定义为00:00,这是一天的开始. It is important to emphasise that this class represents the time of
midnight on any given day. Note that midnight is defined as 00:00,
which is at the very start of a day. 这篇关于Java数据类型仅保留日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 1970年1月1日00:00:00.000 GMT
以来经过的毫秒数.
java.sql.Date
实例包装的实例必须通过设置进行规范化"在小时,分钟,秒和毫秒中将零实例所关联的特定时区.java.sql.Date
instance must be 'normalized' by setting
the hours, minutes, seconds, and milliseconds to zero in the
particular time zone with which the instance is associated. LocalDate
(感谢@cdeszaq)DateMidnight
or LocalDate
(thanks
@cdeszaq) DateMidnight
定义一个日期,其中时间部分固定为午夜.该课程使用时区,因此午夜是当地时间,除非使用UTC时区.
DateMidnight
defines a date where the time component is fixed at
midnight. The class uses a time zone, thus midnight is local unless a
UTC time zone is used.