java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
String date = dateFormat.format(开发者_如何学Gonew Date());
Currently i can use this code to get time in dd/mm/yyyy format.
what i would like to get is date and time with no formatting..so for
15/04/2011 12:00:00 i want :
15042011120000
?
You can use the SimpleDateFormat
class:
SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
String format = s.format(new Date());
You can create your own DateFormat
object (store it statically) and use that in the same way:
dateFormat = new SimpleDateFormat("ddMMyyyyHHmmss");
String date = dateFormat.format(new Date());
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);
精彩评论