Java数据类型只保留日期

Java中的哪种数据类型只能保存日期,不需要时间组件?例如,只是为了存储12/07/2012.我正在将数据持久化到具有日期数据类型的数据库中,因此我正在寻找Java中最佳的等效数据类型.

解决方法

从JDK: javax.sql.Date

A thin wrapper around a millisecond value that allows JDBC to identify
this as an sql DATE value. A milliseconds value represents the number
of milliseconds that have passed since January 1,1970 00:00:00.000 GMT.

To conform with the deFinition of sql DATE,the millisecond values
wrapped by a 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.

或从JodaTimeDateMidnightLocalDate(谢谢
@cdeszaq)

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.

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.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...