java獲取當前時間?
要什么格式的?給你個這樣的“yy-mm-dd hh-mm-ss”//根據時間字符串把天數(shù)加1 public String addOneDay(String time) { String add = null; try { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date timeNow = df.parse(time); Calendar begin=Calendar.getInstance(); begin.setTime(timeNow); begin.add(Calendar.DAY_OF_MONTH,1); add = df.format(begin.getTime()); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return add; }這是加1的你把1改成-1就行了獲取當前時間的函數(shù)://獲取當前時間 public String getTime() { TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); TimeZone.setDefault(tz); Calendar rightNow = Calendar.getInstance(); SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //格式大小寫有區(qū)別 String sysDatetime = fmt.format(rightNow.getTime()); return sysDatetime; }