0
目前,我有一个由四个字符的字符串表示的时间(例2328)。是否有可能获取android当前日期+字符串中表示的时间?Android获取当前日期和整数时间?
,使其在表示“YYYY-MM-DD HH:MM”
目前,我有一个由四个字符的字符串表示的时间(例2328)。是否有可能获取android当前日期+字符串中表示的时间?Android获取当前日期和整数时间?
,使其在表示“YYYY-MM-DD HH:MM”
我做到了通过使用设定功能
String time = message.substring(7, 11);
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY,Integer.parseInt(message.substring(7, 9)));
c.set(Calendar.MINUTE,Integer.parseInt(message.substring(9, 11)));
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
String formattedDate = df.format(c.getTime());
这里来示例函数来格式化,只要你喜欢的日期,希望这有助于
public static String getFormattedDate() {
return getFormattedDate(System.currentTimeMillis());
}
public static String getFormattedDate(long millis) {
if (StringUtils.isEmpty(millis+"") || millis<=0) return "";
return getFormattedDate(new Date(millis));
}
public static String getFormattedDate(Date date) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
return sdf.format(date);
}
catch (Exception ex) {
return "";
}
}