[英]Time value in YYYY-MM-DD HH:MM:SS format
使用休眠從數據庫中獲取值。
DB將timevalue的以下數據作為datetime列(2016-04-11 23:54:11)
Hibernate具有以下數據
<property name="timevalue" type="timestamp">
<column name="timevalue" length="100" />
</property>
我已經聲明如下數據
@Temporal(TemporalType.TIMESTAMP)
private java.util.Date timevalue;
但是當我嘗試獲取數據時,它作為timevalue
返回:
1460399054000
但我需要時間值為YYYY-MM-DD HH:MM:SS
我現在應該怎么做才能修復它?
假設您長時間獲取數據,則可以執行以下操作:
long timeStamp = 1460399054000L; // what you wot from web service/DB
String format = "YYYY-MM-DD HH:mm:SS";
Date date = new Date(timeStamp);
String dateFormat = new SimpleDateFormat(format).format(date);
System.out.println(dateFormat);
這將打印
2016-04-102 20:04:00
您可以嘗試使用喬達圖書館
long geTime= your value;
GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("US/Central"));
calendar.setTimeInMillis(geTime);
DateTime jodaTime = new DateTime(geTime,
DateTimeZone.forTimeZone(TimeZone.getTimeZone("US/Central")));
DateTimeFormatter parser1 = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss");
System.out.println("Get Time : "+parser1.print(jodaTime));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.