-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatecode.java
42 lines (33 loc) · 1.06 KB
/
Datecode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package lfh;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Datecode {
/**
*
*/
@SuppressWarnings("resource")
public static void main(String[] args) throws ParseException {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String fromDate=sc.next(),toDate=sc.next();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date cfromDate = dateFormat.parse(fromDate),ctoDate = dateFormat.parse(toDate);
calc(cfromDate,ctoDate);
}
public static void calc(Date fromDate, Date toDate)
{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance(),c1=Calendar.getInstance();
c.setTime(fromDate);
c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
fromDate=c.getTime();
System.out.println(dateFormat.format(fromDate));
c.setTime(toDate);
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
if(c.after(c1))
c=c1;
toDate=c.getTime();
System.out.println(dateFormat.format(toDate));
}
}