当前位置: 代码迷 >> SQL >> 怎的从java.sql.Timestamp得到java.sql.Date对象
  详细解决方案

怎的从java.sql.Timestamp得到java.sql.Date对象

热度:95   发布时间:2016-05-05 14:01:18.0
怎样从java.sql.Timestamp得到java.sql.Date对象

怎样从java.sql.Timestamp得到java.sql.Date对象

问题虽然简单,也记录一下

String str = "2012-05-02 16:57:23";

java.sql.Timestamp theTimestamp = java.sql.Timestamp.valueOf(str);

java.sql.Date theDate = new java.sql.Date(theTimestamp.getTime());

java.sql.Time theTime = new java.sql.Time(theTimestamp.getTime());

?

?

java.sql.Date的构造方法

javadoc 写道
Date(int year, int month, int day)
Deprecated. instead use the constructor Date(long date)
Date(long date)
Constructs a Date object using the given milliseconds time value.

?

?

?

javadoc 写道
public Date(long date)

Constructs a Date object using the given milliseconds time value. If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT.

Parameters:
date - milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT.

?

?

javadoc 写道
public static Date valueOf(String s)

Converts a string in JDBC date escape format to a Date value.

Parameters:
s - a String object representing a date in in the format "yyyy-mm-dd"
?

?

?

java.sql.Time的构造方法

?

?

javadoc 写道
Time(int hour, int minute, int second)
Deprecated. Use the constructor that takes a milliseconds value in place of this constructor
Time(long time)
Constructs a Time object using a milliseconds time value.

?

?

javadoc 写道
public Time(long time)

Constructs a Time object using a milliseconds time value.

Parameters:
time - milliseconds since January 1, 1970, 00:00:00 GMT; a negative number is milliseconds before January 1, 1970, 00:00:00 GMT

?

?

javadoc 写道
public static Time valueOf(String s)

Converts a string in JDBC time escape format to a Time value.

Parameters:
s - time in format "hh:mm:ss"
Returns:
a corresponding Time object
?

?

?

  相关解决方案