如何在PHP日期时间中添加秒 [英] How to add seconds in a PHP date time

查看:999
本文介绍了如何在PHP日期时间中添加秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在日期时间添加秒。
ex。我有日期时间2009-01-14 06:38:18
我需要在该日期
中添加-750秒,并希望在日期时间中得到结果

How can I add second(s) in a date time. ex. I have date time 2009-01-14 06:38:18 I need to add -750 seconds in that date and want result in datetime

推荐答案

您需要将该日期转换为 unix时间戳,其中此类操作很简单:

You need to convert that date to a unix timestamp, where such operations are trivial:

$unix_timestamp = strtotime('2009-01-14 06:38:18');
$new_string = date('Y-m-d H:i:s', $unix_timestamp - 750);

这篇关于如何在PHP日期时间中添加秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆