java获取前五分钟时间_使用日期操作类(Calendar)获得几秒、几分钟、几小时之前的时间…

  • Post author:
  • Post category:java


public String dealDate(String case_time){

// 日期操作类

Calendar calendar = Calendar.getInstance();

// 当前时间

calendar.setTime(new Date());

SimpleDateFormat sdf = new SimpleDateFormat(

“yyyy-MM-dd HH:mm”);

if(case_time.contains(“秒”)){

int parseInt = Integer.parseInt(case_time.replaceAll(“秒前”, “”));

calendar.add(Calendar.SECOND, -parseInt);

case_time = sdf.format(calendar.getTime());

}else if(case_time.contains(“分钟”)){

int parseInt = Integer.parseInt(case_time.replaceAll(“分钟前”, “”));

calendar.add(Calendar.MINUTE, -parseInt);

case_time = sdf.format(calendar.getTime());

}else if(case_time.contains(“小时”)){

int parseInt = Integer.parseInt(case_time.replaceAll(“小时前”, “”));

cal



版权声明:本文为weixin_39805409原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。