-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeKiller.java
144 lines (111 loc) · 2.76 KB
/
TimeKiller.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import java.util.Date;
import java.util.Scanner;
public class TimeKiller
{
static int year;
static int month;//ïåðåáîð îò 0 äî 12 - arrayåì èëè êàê òàì áûëî
static int day;
static int hour;
static int minute;
static int second;
int errorflag;
static int MaxLength(int month, int year)
{
/*if(month==1) return 31;
if((month==2)&&(year%4==0)) return 28;
if((month==2)&&(year%4!=0)) return 29;
if(month==3) return 31;
if(month==4) return 30;
if(month==5) return 31;
if(month==6) return 30;
if(month==7) return 31;
if(month==8) return 31;
if(month==9) return 30;
if(month==10) return 31;
if(month==12) return 31;
if(month==11) return 30;
if((month<1)||(month>12)||(year<0))
{
System.out.println("Error");
return -1;
}*/
switch(month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
if(year%4==0) return 28;
else return 29;
default:
System.out.println("No such month");
return -1;
}
}
static int MaxLengthCheck(int day,int month,int year,int hour,int minute,int second)
{
if((MaxLength(month,year)==-1)||(day<1)||(day>31)||(MaxLength(month,year)<day)||(hour>24)||(hour<0)||(minute>59)||(minute<0)||(second>59)||(second<0))
{
System.out.print("Wrong date format");
return -1;}
else
{return 1;}
}
TimeKiller(int day1,int month1,int year1,int hour1,int minute1,int second1)
{
//System.out.println("Write wanted date in format DAY MONTH YEAR HOUR MIN");
//Scanner in=new Scanner(System.in);
int count=0;
//do
//{
switch (count)
{
case 0:
day=day1;
System.out.printf("Timekiller day is %d \n", day);
count++;
case 1:
month=month1;
System.out.printf("Timekiller month is %d\n",month);
count++;
case 2:
year=year1;
System.out.printf("Timekiller year is %d\n",year);
count++;
case 3:
hour=hour1;
System.out.printf("Timekiller hour is %d\n",hour);
count++;
case 4:
minute=minute1;
System.out.printf("Timekiller minute is %d\n",minute);
count++;
case 5:
//second=in.nextInt();
second=second1;
System.out.printf("Timekiller second is %d\n",second);
count++;
int d=MaxLengthCheck(day,month,year,hour,minute,second);
//}
//while(in.hasNextInt());
}
}
}
/*String date = "2015-06-18T14:10:15.945158Z";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
Date date1 = simpleDateFormat.parse(date);
Log.i("parse date :", date1.getTime() + "");
} catch (java.text.ParseException e) {
e.printStackTrace();
} */