可能重复: Converting时间戳字符串中的Android 日期
Possible Duplicate: Converting Timestamp as String to Date in android
我的服务器返回一个时间戳1322400600的字符串,在我的Android应用程序,我需要将其转换像2011年11月27日07:00。我不知道如何做到这一点,请帮助我。
My server is returning a timestamp 1322400600 in String, In my android application, i need to convert it like Nov 27, 2011 07:00am. I don't know how to do this please help me out.
- 谢谢 AvMishra
- Thanks AvMishra
解决方案:
我用下面的code,以获得所需的值
I used following code to get the desired value
long dv = Long.valueOf(timestamp_in_string)*1000;// its need to be in milisecond
Date df = new java.util.Date(dv);
String vv = new SimpleDateFormat("MM dd, yyyy hh:mma").format(df);
由车雅米很大的帮助。
great help by Che Jami
推荐答案
您可以使用新java.util.Date(的Long.parseLong(timeInMillis))
。有了这个日期
对象有几种方法可以提取日期在您需要的字符串
格式,最简单的方法使用与Date.toString()
。或者,更恰当,你可以使用的SimpleDateFormat
与你想要的确切模式。
You can use new java.util.Date(Long.parseLong(timeInMillis))
. With this Date
object there are several ways to extract the date in your desired String
format, the simplest way using Date.toString()
. Alternatively, and more appropriately you can use a SimpleDateFormat
with the exact pattern you want.
相关推荐
最新文章