如果想獲取手機的當前系統語言,可以通過locale類獲取,主要方法:locale.getdefault().getlanguage(),返回的是es或者zh;通過locale.getdefault().getcountry()獲取當前國家或地區,返回為cn或us;如果當前手機設定為中文-中國,則使用此方法返回zh-cn,同理可得到其他語言與地區的資訊。
1.首先,如果要程式自動適應系統語言進行轉變,可以在res下新增相應的語言資料夾:如:新增中文,則資料夾命名為values-zh-rcn,如果不清楚需要的名字可以到:e:\android-sdk-windows\platforms\android-8\data\res,如這樣的資料夾下尋找。這樣就可以讓程式自動適應系統的語言來選擇語言。
2.如果我們想在程式內部可以手動地選擇語言則:
a.首先獲得當前的語言或者國家:
string able= getresources().getconfiguration().locale.getcountry();
b.進行判斷:如果是中文則返回的able.equals("cn")
c.進行設定的**為:
//選擇中文
configuration config = getresources().getconfiguration();
displaymetrics dm = getresources() .getdisplaymetrics();
config.locale = locale.simplified_chinese;
getresources().updateconfiguration(config, dm);
d.最後用sharedpreferences儲存當前的語言設定
獲得系統當前時間
方案 優點 僅使用c標準庫 缺點 只能精確到秒級 include include int main void size t strftime char strdest,size t maxsize,const char format,const struct tm timeptr 根據格式字串生成字...
獲得系統當前時間
nsdateformatter nsdformatter nsdateformatter alloc init autorelease nsdformatter setdatestyle nsdateformattershortstyle nsdformatter setdateformat yyy...
獲得當前系統時間
1.首先包括標頭檔案 2.然後 time t rtime 用time t表示的時間 日曆時間 是從乙個時間點 例如 1970年1月1日0時0分0秒 到此時的秒數。在time.h中,我們也可以看到time t是乙個長整型數。3.struct tm timeinfo time rtime timeinf...