Package java.util& amp;软件包java.sql [英] Difference between Date class in Package java.util & Package java.sql

查看:185
本文介绍了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?

推荐答案

java.sql.Date 的JavaDoc

From the JavaDoc of java.sql.Date:


围绕一个毫秒值的薄包装,允许JDBC将其标识为SQL DATE值。毫秒值表示1970年1月1日00:00 00:00之后已经过去的毫秒数。

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.

为了符合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.sql.Time ,它只表示一个时间段,而且还扩展了 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆