在jqueryEasyUI介面將時間以日期加時分秒的格式顯示

來源:互聯網
上載者:User

問題描述:

oracle 10G中使用者表有一個欄位是日期型,資料格式為yyyy-MM-dd HH:mm:ss,最上層顯示時只能顯示成yyyy-MM-dd 後面的 HH:mm:ss不顯示。

經過一番痛苦的原因分析,發現應該將使用者實體的日期類型由java.sql.Date修改成java.util.Date型,並且對 jackson進行如下處理:

private void Test(MyUser user)
{
ObjectMapper mapper = new ObjectMapper();
Writer strWriter = new StringWriter();
try {
// mapper.writeValue(strWriter, user);
System.out.println("時間");
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d;
try {
d = (Date) df.parse("2011-10-12 12:12:12");
user.setCreatedatetime(d);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


System.out.println(user.getCreatedatetime());

// DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SerializationConfig serConfig = mapper.getSerializationConfig();
serConfig.setDateFormat(dateFormat);
DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();
deserializationConfig.setDateFormat(dateFormat);
mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.writeValue(strWriter, user);

} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String userDataJSON = strWriter.toString();
System.out.println(userDataJSON);
}
輸出為:
時間
Wed Oct 12 12:12:12 CST 2011,預設實體類日期輸出格式
{"id":262,"username":"zhaohaiyan","password":"2","createdatetime":"2011-10-12 12:12:12","modifydatetime":"2014-05-15 09:17:05"},經過格式化後顯示。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.