标签:style blog color io java ar for div 2014
1 import java.text.ParseException; 2 import java.text.SimpleDateFormat; 3 import java.util.Calendar; 4 import java.util.Date; 5 6 7 public class TestMinusOneMonth { 8 9 public static void main(String[] args) { 10 String string = "2014-01-01"; 11 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 12 try { 13 Date date = sdf.parse(string); 14 Calendar calendar = Calendar.getInstance(); 15 calendar.setTime(date); 16 calendar.add(Calendar.MONTH, -1); 17 date = calendar.getTime(); 18 string = sdf.format(date); 19 System.out.println(string); //2013-12-01 20 } catch (ParseException e) { 21 e.printStackTrace(); 22 } 23 } 24 }
(Java) 2014年1月1日减一个月涉及时间与字符的转换
标签:style blog color io java ar for div 2014
原文地址:http://www.cnblogs.com/DurantSimpson/p/3990608.html