怎样从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
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值