private static String getSystemDefaultDateFormat(Context context){
String strTimeFormat="";
try{
strTimeFormat = android.provider.Settings.System.getString(context.getContentResolver(),
android.provider.Settings.System.DATE_FORMAT);
}catch(Exception e){
strTimeFormat="dd/MM/yyyy";
}
//防止小米手机有默认值,但是设置中却没有默认选择,获取数据为空的情况
if(strTimeFormat==null||strTimeFormat.equals("")){
strTimeFormat="dd/MM/yyyy";
}
//提前检测是否解析会出错
try{
SimpleDateFormat sdf=new SimpleDateFormat(strTimeFormat);
Date date=new Date();
date.setTime(System.currentTimeMillis());
sdf.format(date);
}catch(Exception e){
strTimeFormat="dd/MM/yyyy";
}
return strTimeFormat;
}
android 获取系统时间格式
最新推荐文章于 2023-10-08 15:03:35 发布