获取系统24小时制时间

/**
* 获取系统时间
*/
private String getDate() {

SimpleDateFormat sDateFormat ;
String mDate;
if(DateFormat.is24HourFormat(context.getApplicationContext())){
sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
mDate = sDateFormat.format(new java.util.Date());
}
else {
String am_pm =Calendar.getInstance().getTime().getHours() >= 12 ? "PM" : "AM";
sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
mDate = sDateFormat.format(new java.util.Date()) + am_pm;
}
return mDate;
}

posted on 2016-02-24 14:49  敬的男人  阅读(141)  评论(0)    收藏  举报