Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions solution/1500-1599/1507.Reformat Date/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ func reformatDate(date string) string {
}
```

### **PHP**

```php
class Solution {
/**
* @param String $date
* @return String
*/
function reformatDate($date) {
$arr = explode(" ", $date);
$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");
$year = $arr[2];
$month = $months[$arr[1]];
$day = intval($arr[0]);
if ($day > 0 && $day < 10) $day = "0".$day;
return $year."-".$month."-".$day;
}
}
```

### **...**

```
Expand Down
20 changes: 20 additions & 0 deletions solution/1500-1599/1507.Reformat Date/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ func reformatDate(date string) string {
}
```

### **PHP**

```php
class Solution {
/**
* @param String $date
* @return String
*/
function reformatDate($date) {
$arr = explode(" ", $date);
$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");
$year = $arr[2];
$month = $months[$arr[1]];
$day = intval($arr[0]);
if ($day > 0 && $day < 10) $day = "0".$day;
return $year."-".$month."-".$day;
}
}
```

### **...**

```
Expand Down
15 changes: 15 additions & 0 deletions solution/1500-1599/1507.Reformat Date/Solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
/**
* @param String $date
* @return String
*/
function reformatDate($date) {
$arr = explode(" ", $date);
$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");
$year = $arr[2];
$month = $months[$arr[1]];
$day = intval($arr[0]);
if ($day > 0 && $day < 10) $day = "0".$day;
return $year."-".$month."-".$day;
}
}