java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
String date = dateFormat.format(new Date());
目前我可以使用此代码以dd / mm / yyyy格式获得时间。
我想得到的是没有格式化的日期和时间..所以
15/04/2011 12:00:00 我想要:
15042011120000
答案 0 :(得分:38)
您可以使用SimpleDateFormat
类:
SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
String format = s.format(new Date());
答案 1 :(得分:4)
您可以创建自己的DateFormat
对象(静态存储)并以相同的方式使用它:
dateFormat = new SimpleDateFormat("ddMMyyyyHHmmss");
String date = dateFormat.format(new Date());
答案 2 :(得分:2)
Calendar c1 = Calendar.getInstance();
String myfrmt = c1.get(Calendar.YEAR) + c1.get(Calendar.MONTH) + c1.get(Calendar.DAY_OF_MONTH) + c1.get(Calendar.HOUR_OF_DAY) + c1.get(Calendar.MINUTE);