本文介紹了在android中將時間戳作為字符串轉(zhuǎn)換為日期的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我從服務(wù)器獲取時間戳值為 1291204449,因此我通過以下方式提取了該值實現(xiàn)處理程序.
I am getting Timestamp value as 1291204449 from server so I extracted the value by implementing handler.
現(xiàn)在我想將時間戳值轉(zhuǎn)換為日期.(但問題在于我的活動中我將此值存儲在字符串變量中,因為處理程序以字符串格式返回).
Now I want to convert timestamp value to date.(But the problem is in my activity I stored this value in a string variable because handler returning in string format).
推薦答案
只要使用 時間類.嘗試類似的方法.
Just use the Time class. Try something similar to this.
Time time = new Time();
time.set(Long.valueOf(yourTimeString));
如果你真的需要 Date 對象,試試這個.
If you really need a Date object just try this.
Date date = new Date(Long.parse(yourTimeString));
這篇關(guān)于在android中將時間戳作為字符串轉(zhuǎn)換為日期的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!