简体   繁体   中英

Android change the format of a string representing time and date

I have the string in the format ss:mm:hh dd/mm/yyyy as for example 58:21:16 20/07/2012 but i want the string to be in the format as dd/mmm/yyyy hh:mm:ss as for example 19/Mar/2012 17:34:58 .

But i am getting format as 20:040:2012 02:40:53 .

Here the string i am passing is static. Anybody having any sort of idea regarding this can help.Any sort of help is appreciated.

Use a capital M for month.

SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy hh:mm:ss");
textView.setText(sdf.format(new Date()));

M stands for month and m for minute.

Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM