[英]How to extract the value of TIME(7) field of MS SQL SERVER 2008 R2 in java?
I am using Apache Meta-model
to extract the values from MS SQL SERVER 2008 R2
database. 我正在使用
Apache Meta-model
从MS SQL SERVER 2008 R2
数据库中提取值。 There is a field in MS SQL SERVER 2008 R2
database of type TIME(7)
whose java equivalent type is java.sql.Time
but java.sql.Time
is NOT showing the milliseconds. MS SQL SERVER 2008 R2
数据库中有一个类型为TIME(7)
的字段,其Java等效类型为java.sql.Time
但java.sql.Time
未显示毫秒。 eg 例如
Actual `TIME(7)` value in database: `12:28:16.9475678`
whereas I getting: `12:28:16`
How to get the Time in milliseconds? 如何获得以毫秒为单位的时间?
Updated: 更新:
When I tried to get milliseconds using org.joda.time.LocalTime
as you can see below: 当我尝试使用
org.joda.time.LocalTime
来获取毫秒org.joda.time.LocalTime
,如下所示:
LocalTime localTime = new LocalTime(((Time)row.getValues()[pos]).getTime());
localTime.toString();
Output: 12:28:16.947
(It showing the round value of 9475678
) 输出:
12:28:16.947
(显示9475678
的舍入值)
After converting it to String
, I am getting the round value of milliseconds 12:28:16.947
. 将其转换为
String
,我得到的舍入值为毫秒12:28:16.947
。 The millisecond precision is lost. 毫秒精度会丢失。 Please suggest how to get the the exact value in millisecond without rounding value?
请提出如何在不取整值的情况下以毫秒为单位获取确切值?
Updated:
更新:
I tried using getNanos() as suggested,but i am getting zero milliseconds except my exact millisecond value like: 我尝试按照建议使用getNanos(),但除我的确切毫秒值外,我得到的是零毫秒:
actual value: 12:28:16.9475678 and i am getting 12:28:16.9470000 实际值:12:28:16.9475678而我得到12:28:16.9470000
code:- 码:-
long timestamp =new Timestamp(((Time)row.getValues()[pos]).getTime()).getNanos();
java.sql.Time doesn't include milliseconds. java.sql.Time不包含毫秒。 Try using java.sql.Timestamp instead, as that will include the fractional seconds.
尝试改用java.sql.Timestamp ,因为这将包括小数秒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.