<分区>
我是安卓新手。现在我正在为时间戳而苦苦挣扎。我将以“2014/10/31 00:49”的形式从 api 获取数据。我需要一个变量中的格式为“OCT 31”,另一个变量中的格式为“00:49”。我该如何解决。提前致谢。
<分区>
我是安卓新手。现在我正在为时间戳而苦苦挣扎。我将以“2014/10/31 00:49”的形式从 api 获取数据。我需要一个变量中的格式为“OCT 31”,另一个变量中的格式为“00:49”。我该如何解决。提前致谢。
最佳答案
看起来很复杂,但完全符合您的需求:
// your input string
String dateInputString = "2014/10/31 00:49";
try {
// obtain date and time from initial string
Date date = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.ROOT).parse(dateInputString);
// set date string
String stringDate = new SimpleDateFormat("MMM dd", Locale.US).format(date).toUpperCase(Locale.ROOT);
// set time string
String stringTime = new SimpleDateFormat("HH:mm", Locale.ROOT).format(date);
} catch (ParseException e) {
// wrong input
}
字符串日期
: OCT 31
字符串时间
:00:49
关于android - 如何将 "YYYY/MM/DD HH:MM"转换为 "MMM DD"和 "HH:MM"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22666272/