开发者

Date format in java [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

how to convert seconds_since_the_beginning_of_this_epoch to date format in java..?

hi i have "1304054138"开发者_运维知识库 in ssboetod . I want to display it in this "21 Apr 2011 11:46:00 AM IST" format. How i can do this in java code... ?


SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy hh:mm:ss a z")
String result = sdf.format(new Date(timestamp));

if timestamp is a String, you can obtain the long version by calling Long.parseLong(string)


Like this:

// 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜