欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解析android中系統(tǒng)日期時(shí)間的獲取

 更新時(shí)間:2013年06月17日 09:26:09   作者:  
本篇文章是對(duì)在android中,如何系統(tǒng)日期時(shí)間獲取的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
復(fù)制代碼 代碼如下:

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);    

可以獲取當(dāng)前的年月時(shí)分,也可以分開(kāi)寫(xiě):
復(fù)制代碼 代碼如下:

SimpleDateFormat    sDateFormat    =   new    SimpleDateFormat("yyyy-MM-dd    hh:mm:ss");    
String    date    =    sDateFormat.format(new    java.util.Date()); 

如果想獲取當(dāng)前的年月,則可以這樣寫(xiě)(只獲取時(shí)間或秒種一樣):
Java代碼
復(fù)制代碼 代碼如下:

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM"); 
String date=sdf.format(new java.util.Date()); 

當(dāng)然還有就是可以指定時(shí)區(qū)的時(shí)間(待):
復(fù)制代碼 代碼如下:

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

如何獲取Android系統(tǒng)時(shí)間是24小時(shí)制還是12小時(shí)制
復(fù)制代碼 代碼如下:

 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");
        }

復(fù)制代碼 代碼如下:

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獲取
復(fù)制代碼 代碼如下:

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)

利用Time獲取
復(fù)制代碼 代碼如下:

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;

唯一不足是取出時(shí)間只有24小時(shí)模式.

相關(guān)文章

最新評(píng)論