从DB中检索java中的完整日期

时间:2016-05-16 15:29:40

标签: java sql-server datetime servlets

我有一个java servlet,它调用名为OAVDbUtil.java的java类中的方法,以从SQL数据库中获取日期。我可以检索日期,但不能检索完整的值。在SQL Server数据库中,该字段为“EventTime”,是一个日期时间字段,是日期数据的示例;

2015-02-16 11:48:15.730

在OAVDbUtil.java中,我有代码来检索结果集中的值并将其放在这样的变量中,其中Date的类型为java.sql.Date

Date loginDate = myRs.getDate("EventTime");

但它将数据检索为“2015-02-16”。如何将日期检索为“2015-02-16 11:48:15.730”?

2 个答案:

答案 0 :(得分:3)

令人困惑,但重要的是要注意,与<button id="click_btn_one" onclick="drop()">Click here</button> <div id="divSeven" data-dropdown class='fade'>This is div seven</div> <div id="divSix" data-dropdown class='fade'>This is div six</div> <div id="divFive" data-dropdown class='fade'>This is div five</div> <div id="divFour" data-dropdown class='fade'>This is div four</div> <div id="divThree" data-dropdown class='fade'>This is div three</div> <div id="divTwo" data-dropdown class='fade'>This is div two</div> <div id="divOne" data-dropdown class='fade'>This is div one</div> function drop(){ var elems = document.querySelectorAll('[data-dropdown]'); var offset = 50; for(var i = 0; i < elems.length; i++){ elems[i].className = 'fade in'; elems[i].style.top = (offset * i) + 'px'; } } #divSeven {position:absolute; top:-100px; left:0px; height:50px; width:200px; background:#000; color:#fff} #divSix {position:absolute; top:-100px; left:0px; height:50px; width:200px; background:#111; color:#fff} #divFive {position:absolute; top:-100px; left:0px; height:50px; width:200px; background:#222; color:#fff} #divFour {position:absolute; top:-100px; left:0px; height:50px; width:200px; background:#333; color:#fff} #divThree {position:absolute; top:-100px; left:0px; height:50px; width:200px; background:#444; color:#fff} #divTwo {position:absolute; top:-100px; left:0px; height:50px; width:200px; background:#555; color:#fff} #divOne {position:absolute; top:-100px; left:0px; height:50px; width:200px; background:#666; color:#fff} .fade { opacity: 0; transition: top 0.8s ease-in 0s, opacity 1s ease-in 0s; } .fade.in { opacity: 1; } 不同,do { status=fscanf(fp,"%d %lf %ld %c",&ids[i], &balances[i], &phones[i], &types[i]); i++; }while(status != -1 ); 确实只是日期。时间包含在内。

根据您的需要,您应该使用java.util.Date

答案 1 :(得分:0)

使用getTimestamp

Timestamp loginDate = myRs.getTimestamp("EventTime");

使用SimpleDateFormat将其转换为字符串。