Created
September 15, 2017 01:25
-
-
Save trydofor/490fe17000c464879fdb7cd69db30605 to your computer and use it in GitHub Desktop.
日期计算
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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