38 lines
757 B
PHP
38 lines
757 B
PHP
<?php
|
|
|
|
namespace App\Utils;
|
|
|
|
use DateTime;
|
|
|
|
class DateTimeUtil
|
|
{
|
|
public static function isDate($string)
|
|
{
|
|
$string = str_replace('/', '-', $string);
|
|
$stamp = strtotime($string);
|
|
|
|
if (is_numeric($stamp)) {
|
|
|
|
$month = date('m', $stamp);
|
|
$day = date('d', $stamp);
|
|
$year = date('Y', $stamp);
|
|
|
|
return checkdate($month, $day, $year);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static function isFormattedCorrectly($date, $format = 'Y-m-d H:i:s')
|
|
{
|
|
if (self::isDate($date)) {
|
|
|
|
$createdDate = DateTime::createFromFormat($format, $date);
|
|
|
|
return $createdDate && $createdDate->format($format) === $date;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|