日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

安卓杂记(一) 获取时间总结整理

發(fā)布時(shí)間:2025/3/15 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安卓杂记(一) 获取时间总结整理 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.配合使用SimpleDateFormat與Date:import java.text.SimpleDateFormat; SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss "); Date curDate = new Date(System.currentTimeMillis());//獲取當(dāng)前時(shí)間 String str = formatter.format(curDate);

若要顯示日期,可用‘E’字符,默認(rèn)為英文,若要變?yōu)橹形?#xff0c;可參考如下代碼:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 E",Locale.CHINA);

也可以這樣寫(xiě):

df=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.CHINA); System.out.println(df.format(new Date()));

?

2.獲取Android小時(shí)制(24小時(shí)制還是12小時(shí)制):

ContentResolver cv = this.getContentResolver();String strTimeFormat = android.provider.Settings.System.getString(cv,android.provider.Settings.System.TIME_12_24);if(strTimeFormat.equals("24")){Log.i("activity","24");}


?

Calendar c = Calendar.getInstance(); 取得系統(tǒng)日期:year = c.get(Calendar.YEAR)month = c.grt(Calendar.MONTH)day = c.get(Calendar.DAY_OF_MONTH) 取得系統(tǒng)時(shí)間:hour = c.get(Calendar.HOUR_OF_DAY);minute = c.get(Calendar.MINUTE)


3.利用Calender獲取時(shí)間:

Calendar c = Calendar.getInstance(); 取得系統(tǒng)日期:year = c.get(Calendar.YEAR)month = c.grt(Calendar.MONTH)day = c.get(Calendar.DAY_OF_MONTH) 取得系統(tǒng)時(shí)間:hour = c.get(Calendar.HOUR_OF_DAY);minute = c.get(Calendar.MINUTE)Calendar c = Calendar.getInstance(); 取得系統(tǒng)日期:year = c.get(Calendar.YEAR)month = c.grt(Calendar.MONTH)day = c.get(Calendar.DAY_OF_MONTH) 取得系統(tǒng)時(shí)間:hour = c.get(Calendar.HOUR_OF_DAY);minute = c.get(Calendar.MINUTE)


4.利用Time獲取時(shí)間:

Time t=new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone資料。 t.setToNow(); // 取得系統(tǒng)時(shí)間。 int year = t.year; int month = t.month; int date = t.monthDay; int hour = t.hour; // 0-23 int minute = t.minute; int second = t.second;

注:Time取出的只有24小時(shí)制



?

轉(zhuǎn)載于:https://www.cnblogs.com/jscitlearningshare/p/4340651.html

總結(jié)

以上是生活随笔為你收集整理的安卓杂记(一) 获取时间总结整理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。