Skip to content

Commit 6c9870a

Browse files
authored
feat: add php solution to lc problem: No.1507 (doocs#1023)
1 parent 60c04ca commit 6c9870a

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

solution/1500-1599/1507.Reformat Date/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ func reformatDate(date string) string {
123123
}
124124
```
125125

126+
### **PHP**
127+
128+
```php
129+
class Solution {
130+
/**
131+
* @param String $date
132+
* @return String
133+
*/
134+
function reformatDate($date) {
135+
$arr = explode(" ", $date);
136+
$months = array("Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12");
137+
$year = $arr[2];
138+
$month = $months[$arr[1]];
139+
$day = intval($arr[0]);
140+
if ($day > 0 && $day < 10) $day = "0".$day;
141+
return $year."-".$month."-".$day;
142+
}
143+
}
144+
```
145+
126146
### **...**
127147

128148
```

solution/1500-1599/1507.Reformat Date/README_EN.md

+20
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,26 @@ func reformatDate(date string) string {
110110
}
111111
```
112112

113+
### **PHP**
114+
115+
```php
116+
class Solution {
117+
/**
118+
* @param String $date
119+
* @return String
120+
*/
121+
function reformatDate($date) {
122+
$arr = explode(" ", $date);
123+
$months = array("Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12");
124+
$year = $arr[2];
125+
$month = $months[$arr[1]];
126+
$day = intval($arr[0]);
127+
if ($day > 0 && $day < 10) $day = "0".$day;
128+
return $year."-".$month."-".$day;
129+
}
130+
}
131+
```
132+
113133
### **...**
114134

115135
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
/**
3+
* @param String $date
4+
* @return String
5+
*/
6+
function reformatDate($date) {
7+
$arr = explode(" ", $date);
8+
$months = array("Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12");
9+
$year = $arr[2];
10+
$month = $months[$arr[1]];
11+
$day = intval($arr[0]);
12+
if ($day > 0 && $day < 10) $day = "0".$day;
13+
return $year."-".$month."-".$day;
14+
}
15+
}

0 commit comments

Comments
 (0)