本文介绍了Package java.util& amp;软件包java.sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在java中, java.util java.sql 包中都包含一个日期类,那么他们有什么区别?

In java, both the java.util and the java.sql package contain a Date class, So what is the difference between them?

如果一个 Date 类在Java中存在,那么需要另外一个 Date class?

If one Date class is present in Java then what is the need of another Date class?

推荐答案

从的JavaDoc

From the JavaDoc of java.sql.Date:

为了符合SQL DATE的定义,毫秒值由 java.sql.Date 实例包装,必须通过将实例所在的特定时区中的小时,分​​钟,秒和毫秒设置为零来实现归一化

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.

说明: A java.util.Date 表示日期和时间,一个 java.sql.Date 只表示一个日期(java.sql.Date的补码是,它只表示一个时间段,而且还扩展了 java.util.Date )。

Explanation: A java.util.Date represents date and time of day, a java.sql.Date only represents a date (the complement of java.sql.Date is java.sql.Time, which only represents a time of day, but also extends java.util.Date).

这篇关于Package java.util& amp;软件包java.sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 23:17