我怎样才能从时间戳MM / DD / YY格式得到日期 [英] How can I get Date in MM/DD/YY format from Timestamp
问题描述
我想从一个时间戳得到 MM / DD / YY
格式的日期。
I want to get the Date in MM/DD/YY
format from a timestamp.
我已经使用了以下方法,但它不给出正确的输出
I have used the below method but it does not gives proper output
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(Long.parseLong(1306249409));
Log.d("Date--",""+cal.DAY_OF_MONTH);
Log.d("Month--",""+cal.MONTH);
Log.d("Year--",""+cal.YEAR);
但它给出了类似下面的输出
But its gives the output like below
日期 - 5 月 - 2 年 - 1
Date--5 Month--2 Year--1
正确的日期是2010年5月24时间戳 - 1306249409
The correct date is 24 May 2010 for Timestamp - 1306249409
请注意 - 如果收到由用在我的应用程序web服务时间戳
Note - Timestamp is received by a webservice which is used in my application.
推荐答案
更好的办法
只需使用<一个href="http://developer.android.com/reference/java/text/SimpleDateFormat.html"><$c$c>SimpleDateFormat$c$c>
new SimpleDateFormat("MM/dd/yyyy").format(new Date(timeStampMillisInLong));
错误在你的方法
DAY_OF_MONTH
,月
,..等都是使用只是不断的int值日历
类
内部
DAY_OF_MONTH
,MONTH
, .. etc are just constant int value used by Calendar
class
internally
您可以通过 cal.get(Calendar.DATE)
度日 CAL
psented日期重新$ P $
You can get the date represented by cal
by cal.get(Calendar.DATE)
这篇关于我怎样才能从时间戳MM / DD / YY格式得到日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!