日期:2014-05-17 浏览次数:20700 次
SimpleDateFormat sdf = new SimpleDateFormat("HHmmss");
Date date = sdf.parse("140220");
public static void main(String[] arg) throws ParseException {
String srcStr = "140654";
SimpleDateFormat sdf = new SimpleDateFormat("HHmmss");
Date date = sdf.parse(srcStr);
date.setMinutes(date.getMinutes() - 3);
SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
System.out.println(sdf2.format(date));
}
public static java.util.Date getDateBeforeMinute(Date d, int minutes)
{
Calendar now = Calendar.getInstance();
now.setTime(d);
now.set(Calendar.DATE, now.get(Calendar.MINUTE) - minutes);
return now.getTime();
}
public static void main(String[] arg) {
String srcStr = "140654";
SimpleDateFormat sdf = new SimpleDateFormat("HHmmss");
Calendar calendar = new GregorianCalendar();
try {
calendar.setTime(sdf.parse(srcStr));
calendar.add(calendar.MINUTE, -3);//减3分钟
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}