forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1507.java
64 lines (60 loc) · 1.8 KB
/
_1507.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
package com.fishercoder.solutions;
public class _1507 {
public static class Solution1 {
public String reformatDate(String date) {
String[] dates = date.split(" ");
return dates[2] + "-" + getMonth(dates[1]) + "-" + getDay(dates[0]);
}
private String getDay(String day) {
String formatedDay = day.substring(0, day.length() - 2);
if (formatedDay.length() == 1) {
return "0" + formatedDay;
}
return formatedDay;
}
private String getMonth(String month) {
String result = "";
switch (month) {
case "Jan":
result = "01";
break;
case "Feb":
result = "02";
break;
case "Mar":
result = "03";
break;
case "Apr":
result = "04";
break;
case "May":
result = "05";
break;
case "Jun":
result = "06";
break;
case "Jul":
result = "07";
break;
case "Aug":
result = "08";
break;
case "Sep":
result = "09";
break;
case "Oct":
result = "10";
break;
case "Nov":
result = "11";
break;
case "Dec":
result = "12";
break;
default:
result = "";
}
return result;
}
}
}