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


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

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

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


posted on 2017-06-24 16:55  wgwyanfs  阅读(679)  评论(0编辑  收藏  举报

导航