Skip to content

Instantly share code, notes, and snippets.

@trydofor
Created September 15, 2017 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trydofor/490fe17000c464879fdb7cd69db30605 to your computer and use it in GitHub Desktop.
Save trydofor/490fe17000c464879fdb7cd69db30605 to your computer and use it in GitHub Desktop.
日期计算
public static void main(String[] args) throws ParseException {
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.set(2017,10,30); // 月份从0开始,10标识11月
System.out.println(s.format(c.getTime()));
c.add(Calendar.MONTH,3); // 月末对齐
System.out.println(s.format(c.getTime()));
Date d = s.parse("2017-13-45"); // 会有解析错误么?不会
System.out.println(s.format(d)); // 是情人节
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment