view raw
patrick1980 patrick1980 - 5 months ago 46
Android Question

SimpleDateFormat did not work

I wanted to change the format (from 12 to 24hours) saves your time and found on stack how to do it

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy HH:mm:ss");

String currentDateTimeString = dateFormat.getDateTimeInstance().format(new Date());

but not that still works and saves Form A.M/P.M

why it does not work?


You call the static method getDateTimeInstance(), which creates a new SimpleDateFormat instance, instead of using the SimpleDateFormat you just created:

dateFormat.format(new Date());

Also, you're using mm (minutes) instead of MM (months).