本文介紹了Java簡(jiǎn)單的時(shí)間戳到日期轉(zhuǎn)換的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我今天一直在努力尋找這個(gè)問(wèn)題的答案,但有很多相互矛盾的信息......
I've been trying to find the answer to this for a while today and there's just so much contradictory information....
我想做的是在 android 中獲取當(dāng)前的 unix 時(shí)間戳,然后將其轉(zhuǎn)換為允許我 getHours() 和 getMinutes() 的格式.
What I'd like to do is get a current unix timestamp in android, and then convert it to a format that allows me to getHours() and getMinutes().
我目前正在這樣做:
int time = (int) (System.currentTimeMillis());
Timestamp ts = new Timestamp(time);
mHour = ts.getHours();
mMinute = ts.getMinutes();
但它沒(méi)有給我一個(gè)正確的小時(shí)或分鐘值(它返回 03:38 代表當(dāng)前東海岸時(shí)間 13:33).
But it's not giving me a correct value for hour or minute (it's returning 03:38 for the current East-coast time of 13:33).
推薦答案
這可行:
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
Date date = cal.getTime();
mHour = date.getHours();
mMinute = date.getMinutes();
這篇關(guān)于Java簡(jiǎn)單的時(shí)間戳到日期轉(zhuǎn)換的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!