Android开发之获取系统12/24小时制的时间


Android开发之获取系统12/24小时制的时间

//通过DateFormat获取系统的时间
String currentTime=DateFormat.format("yyyy-MM-dd hh-mm-ss", new Date()).toString();
currentTime="通过DateFormat获取的时间:
"+currentTime;		
//通过SimpleDateFormat获取24小时制时间
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss", Locale.getDefault());		
currentTime+="
"+"通过SimpleDateFormat获取24小时制时间:
"+sdf.format(new Date());
//通过SimpleDateFormat获取12小时制时间
sdf=new SimpleDateFormat("yyyy-MM-dd hh-mm-ss", Locale.getDefault());	
currentTime+="
"+"通过SimpleDateFormat获取12小时制时间:
"+sdf.format(new Date());

注意:通过DateFormat方式仅仅能获取12小时制时间


原文地址:https://www.cnblogs.com/wgwyanfs/p/7073782.html