I want to add two timestamps, like in this example:
$created_at = "2018-07-23 12:15:43";
$is_expired = $created_at + 30mins;
The content of $is_expired
should be 2018-07-23 12:45:43
Using Carbon you can do
$is_expired = $created_at->addMinutes(30);
Carbon is installed by default in Laravel and your dates should be automatically mutated by Laravel.
If the date is not mutated then you can parse them to Carbon instance using Carbon::Parse($created_at)
Or if you have $dates = []
in your model you should add the created_at
in it like so
protected $dates = [
'created_at',
'updated_at',
'deleted_at'
];
You can use core php functions:
//set timezone
date_default_timezone_set('GMT');
$date = new DateTime();
$created_at = $date->format('U = Y-m-d H:i:s');
$unixTimestamp = time() + 1800; // 30 * 60
$date = new DateTime();
$date->setTimestamp($unixTimestamp);
$is_expired = $date->format('U = Y-m-d H:i:s');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.