2012-02-25 51 views
0

我在我的應用程序中安裝了一個推送飼料。 但日期格式不正確。正確的日期格式twiiter在應用程序中餵食

它現在顯示如下:星期六,2012年2月22日22時39分32秒+0000但我希望它在荷蘭和像這樣:22:39u 2012年2月25日(荷蘭語格式和命名)。

或者,也許如果可能的話: 「大約2個小時前」

我用這個教程的代碼: http://codehenge.net/blog/2011/05/android-programming-tutorial-a-simple-twitter-feed-reader/

我說:

((JSONObject)t).get("profile_image_url").toString() 

回答

0

由於意見上說頁面,您需要使用SimpleDateFormat

+0

是的,但我不知道在何處以及如何,我想它的toString後前......我真的沒有一個線索 – 2012-02-26 00:17:56

1

對於那些仍在尋找解決方案的人:

Step-1首先我們需要將twitter feed格式轉換爲Date Obj。像Twitter的JSON響應我們得到的值創建爲: -

Sat Apr 02 17:14:28 +0000 2016 

對應的格式將是"EEE MMM dd hh:mm:ss Z yyyy" Refer here for how to use formatting pattern letters

所以代碼cobert它迄今對象將是:

//Existing Format 
    SimpleDateFormat createdDateFormat = new SimpleDateFormat("EEE MMM dd hh:mm:ss Z yyyy");; 
    Date dateObj = createdDateFormat.parse(date); 

步驟2轉換爲使用如下新的格式模式這個日期的OBJ到你需要的格式:

//changing to new format 
createdDateFormat = new SimpleDateFormat("MMM dd,yyyy hh:mm a"); 
date = createdDateFormat.format(dateObj); 

最終輸出是: -

Apr 03,2016 03:06 AM