简体   繁体   English

Android更改代表时间和日期的字符串格式

[英]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 . 我有格式为ss:mm:hh dd/mm/yyyy的字符串,例如58:21:16 20/07/2012但我希望字符串的格式为dd/mmm/yyyy hh:mm:ss ,例如19/Mar/2012 17:34:58

But i am getting format as 20:040:2012 02:40:53 . 但是我正在将格式设置为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. 使用大写的M作为月份。

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

M stands for month and m for minute. M代表月份, m代表分钟。

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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