How can I work with dates before 1900 in PHP?

后端 未结 2 607
攒了一身酷
攒了一身酷 2020-12-04 02:04

I am using PHP and jQuery to build an interactive timeline which needs to display dates between 1500 and 2020. I usually use PHP\'s strtotime function when work

2条回答
  •  执笔经年
    2020-12-04 02:17

    Using the wonderful Carbon Library, dates in the past are not a problem:

    $date = Carbon::now();
    $date->subCenturies(23);
    echo $date->format('Y-m-d');
      // -0282-03-15
    

    This works for dates where humans have been around. For everything else, using a date (with day and month, set on the AC/BC scale) does not make a lot of sense.

提交回复
热议问题