在实际开发中,需求往往是五花八门,时间格式化成年月日,时分秒是很正常的需求,如果需要改成月-日 时:分格式
方案一:两个simpleDateFormate
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");Date parse = simpleDateFormat .parse( aAccountRecordVO .getShowPaySuccessTime());
sdf.format(parse)
方案二:日期转日历,然后使用日历的方法单独获取月,日,时,分在拼接
Calendar instance = Calendar.getInstance();
Date parse = simpleDateFormat.parse(aAccountRecordVO.getShowPaySuccessTime()); instance.setTime(parse); String datestr = (instance.get(Calendar.MONTH) + 1) + "-" + instance.get(Calendar.DAY_OF_MONTH) + " " + instance.get(Calendar.HOUR_OF_DAY) + ":" + instance.get(Calendar.MINUTE);