public static String before30Day(String time) { DateFormat dateFromat = new SimpleDateFormat(TIME_STAMP_STANDARD); try { Date parse = dateFromat.parse(time); Calendar cal = Calendar.getInstance();// get a calendar by using default timezone and language cal.setTime(parse); cal.add(Calendar.DAY_OF_MONTH, -30); Date date = cal.getTime(); return dateFromat.format(date); } catch (ParseException e) { e.printStackTrace(); } return null; }
public static void main (String [] args) { // get eight districts in Eastern Time Calendar c = Calendar.getInstance (TimeZone.getTimeZone ( " GMT + 08: 00 " )); // get in int year = c. GET ( Calendar.YEAR); // get the month, will be less one day. So + 1'd int month The C =. GET (the Calendar.MONTH) + . 1 ; // get the current number of days int Day = C. GET (Calendar.DAY_OF_MONTH); c.add (Calendar.YEAR, . 5 ); c.add (Calendar.DATE, + 10 ); // get the current hour int H = C. GET (Calendar.HOUR_OF_DAY); // get the current minute int m = C. GET (Calendar.MINUTE); // get the current second int SE = C. GET (Calendar.SECOND); the SimpleDateFormat S = new new the SimpleDateFormat ( " YYYY the mM-dd-HH: mm: SS " ); // formatting time format String Now = s.format (c.getTime ( )); // get the current date format (Obj): formatting an object to produce a string. The System. OUT .println ( " Current Time: " + year + " - " + month The + " - " + Day + " " + H + " : " + m + " : " + SE); . The System OUT .println ( " current date Now: " + Now); }