可能重複:
how to convert seconds_since_the_beginning_of_this_epoch to date format in java..?日期格式在Java
您好,我在ssboetod有 「1304054138」。我想在這個「2011年4月21日11:46:00 AM IST」格式中顯示它。我如何在Java代碼中做到這一點...?
可能重複:
how to convert seconds_since_the_beginning_of_this_epoch to date format in java..?日期格式在Java
您好,我在ssboetod有 「1304054138」。我想在這個「2011年4月21日11:46:00 AM IST」格式中顯示它。我如何在Java代碼中做到這一點...?
SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy hh:mm:ss a z")
String result = sdf.format(new Date(timestamp));
如果timestamp
是String
,您可以通過調用Long.parseLong(string)
像這樣獲得的長版:
// creat date format
DateFormat dateFormat = DateFormat.getDateTimeInstance(
DateFormat.LONG, DateFormat.LONG);
// set time zone
dateFormat.setTimeZone(TimeZone.getTimeZone("IST"));
// create and format date
String formattedDate = dateFormat.format(new Date(Long.valueOf("1304054138")));
// write out
System.out.println(formattedDate);
它不完全重複的,因爲日期格式部分沒有覆蓋好於其他問題。 – Bozho 2011-04-29 09:18:01