Android获得当前系统时间、星期几、周几、十二小时制、二十四小时制

mFormat = new SimpleDateFormat("yyyy-MM-dd");//日期格式化 年月日
weekFormat = new SimpleDateFormat("EEEE");//日期格式化 星期几
twentyFourMinuteTimeFormat = new SimpleDateFormat("HH:mm:ss");//日期格式化 小时:分:秒 HH代表24小时制
twentyFourTimeFormat = new SimpleDateFormat("HH:mm");//日期格式化 小时:分
twelveMinuteTimeFormat = new SimpleDateFormat("hh:mm:ss");//日期格式化 小时:分:秒  hh代表12小时制
twelveTimeFormat = new SimpleDateFormat("hh:mm");//日期格式化 小时:分
twelveTimeFormat = new SimpleDateFormat("E");//日期格式化 周几
SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒 EEEE");//日期格式化 xx年xx月xx日 xx时xx分xx秒 星期几
currentTimeMillis = System.currentTimeMillis();//获取系统时间 long类型
 mDate = new Date(currentTimeMillis);//把获取到的时间值转为时间格式
mFormat.format(mDate);//把时间格式按我们自定义的格式转换
 附上SimpleDateFormat 的sdk地址:http://www.android-doc.com/reference/java/text/SimpleDateFormat.html
区分十二小时制的上午和下午使用:
Calendar calendar = Calendar.getInstance();
int i = calendar.get(Calendar.AM_PM);

i=0代表是上午。i=1代表是下午,可根据i的值去得到是上午还是下午

猜你喜欢

转载自blog.csdn.net/freak_csh/article/details/79625539
今日推荐