2013-03-14 61 views
-1

例如: 我能得到時間戳將UNIX時間戳轉換爲所需的任何格式?

String date="123456765343"; 
    final Calendar cal = Calendar.getInstance(); 
    cal.setTimeInMillis(Long.parseLong(date)*1000); 
    Date d = cal.getTime(); // now this reprents the unix timestamp 

我想有日期看起來像這樣:

14 /三月/ 2013下午六點31分34秒

+0

的典型案例http://whathaveyoutried.com – njzk2 2013-03-14 16:37:44

回答

4

你將不得不使用SimpleDateFormat(你不需要Calendar):

Date d = new Date(Long.parseLong(date) * 1000); 
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy hh:mm:ss a"); 
System.out.println(sdf.format(d)); 
+0

謝謝你,它的工作,你是對的,我不需要'日曆' – Alex 2013-03-14 16:49:32

+0

一些資源解釋更多:http://developer.android.com/reference/java/text/DateFormat.html,http://developer.android.com/reference/java/text/SimpleDateFormat。 HTML。不要忘記地區! – Timmetje 2013-03-14 16:49:54

相關問題