Ben formatında 08/24/2010 bir dize tarihi alır ve bir zaman damgası haline dönüşür bir işlevi var. Ben sorunu böyle 2090/08/24 gibi tarihler yanlış dönüştürülür olmasıdır.
İşte benim fonksiyonudur:
/**
* Converts a date to a timestamp
* for a date formatted such as: 08/24/2010 12:00:00, 08-24-2010 12:00:00 or 08/24/2010
*
* @param string date
* @return string
*/
public static function dateToTimeStamp($date)
{
if (!strstr($date, ' ')) $date .= ' ' . date('h:i:s');
list($date, $time) = explode(' ', $date);
list($month, $day, $year) = (strstr($date, '/') ? explode('/', $date) : explode('-', $date));
list($hour, $minute, $second) = explode(':', $time);
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
return date('Y-m-d h:i:s', $timestamp);
}
Ben sadece 2090/09/30 geçti ve ben geri 1969/12/31 04:00:00 olsun ama ben 2020/09/30 geçtiğinde, ben 2020/09/30 08:54:44 geri almak.