2012-02-20 54 views
0

我給的輸入作爲milliseconds和我得到輸出Sat Aug 13 14:00:00 GMT+05:30 2011日期Formater in j2me?

如:

Date resultdate = new Date(1313224200000L); 
System.out.println("Date: " + resultdate); 

您將如何格式化這個日期13-08-2011和時間14:00?
任何人都可以幫我做嗎?

回答

1

你可以試試下面的方法相同,

public static String getDate(long currentTimeMillis) 
{ 
    Date today = new Date(currentTimeMillis); 
    DateField date = new DateField("", DateField.DATE_TIME, TimeZone.getTimeZone("GMT+5:30")); 
    date.setDate(today); 

    Calendar cal = Calendar.getInstance(); 
    cal.setTime(today); 

    String dateStr = "" + getTwoDigitStr(cal.get(Calendar.DATE)) + "-" + getTwoDigitStr(cal.get(Calendar.MONTH)+1) + "-" + cal.get(Calendar.YEAR); 

    return dateStr; 
} 

public static String getTime (long currentTimeMillis) 
{ 
    Date today = new Date(currentTimeMillis); 
    DateField date = new DateField ("", DateField.TIME, TimeZone.getTimeZone("GMT +5:30") ); 
    date.setDate(today); 

    Calendar cal = Calendar.getInstance(); 
    cal.setTime(today); 

    String timeStr = "" + cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE); 
    return timeStr; 
} 
+0

感謝的人它的工作好...我怎麼能變成最新最快的格式? – selladurai 2012-02-20 12:04:12

+0

它非常簡單的過程,首先嚐試你自己。否則我會在稍後告訴你。 – Android 2012-02-20 12:06:03

+0

它應該在24小時內返回您的時間,在這裏它工作正常,只需檢查您的手機設置。 – Android 2012-02-20 12:12:45