strtotime() and Pre-1970 Dates
Using strtotime() to process dates before 1970 can pose challenges due to its limited range. To address this issue, check your PHP version and platform. Consider upgrading if necessary.
Alternatively, for more flexibility in handling wider date ranges, consider using PHP's DateTime objects. They allow for dates far beyond the 13 Dec 1901 to 19 Jan 2038 range.
Procedural Approach:
$date = date_create($row['value']); if (!$date) { $e = date_get_last_errors(); foreach ($e['errors'] as $error) { echo "$error\n"; } exit(1); } echo date_format($date, "F j, Y");
OOP Approach:
try { $date = new DateTime($row['value']); } catch (Exception $e) { echo $e->getMessage(); exit(1); } echo $date->format("F j, Y");
The above is the detailed content of How Can I Handle Pre-1970 Dates with PHP\'s `strtotime()` and Alternatives?. For more information, please follow other related articles on the PHP Chinese website!