1.可以为12小时或者24小时制
SimpleDateFormat shijian = new SimpleDateFormat("HH:mm:ss");//当参数为hh时为12小时制的,大写就为24小时制的,还可以参数设置为“yyyy-MM-dd hh:mm:ss”
参数的设置可以随意,例如:"yyyy-MM"只要年月,等等组合都可,自动的对应的符号,具体的中间的连接符之类的都可以自己设定eg:“yyyy年MM月dd日”
String addX=shijian.format(new java.util.Date());//下面语句获取系统时间,具体时间是12还是24小时制的要看format中的设置
2.可以为12小时或者24小时制
- import java.text.SimpleDateFormat;
- SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss ");
- Date curDate = new Date(System.currentTimeMillis());//获取当前时间
- String str = formatter.format(curDate);
- df=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.CHINA);
- System.out.println(df.format(new Date()));
4.
如何获取Android系统时间是24小时制还是12小时制
- ContentResolver cv = this.getContentResolver();
- String strTimeFormat = android.provider.Settings.System.getString(cv,
- android.provider.Settings.System.TIME_12_24);
- if(strTimeFormat.equals("24"))
- {
- Log.i("activity","24");
- }
- Calendar c = Calendar.getInstance();
- 取得系统日期:year = c.get(Calendar.YEAR)
- month = c.grt(Calendar.MONTH)
- day = c.get(Calendar.DAY_OF_MONTH)
- 取得系统时间:hour = c.get(Calendar.HOUR_OF_DAY);
- minute = c.get(Calendar.MINUTE)
- Time t=new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。
- t.setToNow(); // 取得系统时间。
- int year = t.year;
- int month = t.month;
- int date = t.monthDay;
- int hour = t.hour; // 0-23
- int minute = t.minute;
- int second = t.second;