从日期减去6小时('g:i a',strtotime($ time_date_data)); [英] subtract 6 hours from date('g:i a', strtotime($time_date_data));

查看:147
本文介绍了从日期减去6小时('g:i a',strtotime($ time_date_data));的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将通用时间代码转换为更加用户友好的代码.

I am using the following code to transform a universal time code into something a little more user friendly.

$meeting_time = date('g:i a', strtotime($time_date_data));

但是现在我需要从Meeting_time中减去6个小时.我应该在上面的代码之后执行此操作,还是可以将其用于相同的date函数?

But now I need to subtract 6 hours from meeting_time. Should I do it after the code above or can I work it into the same date function?

类似的东西:

$meeting_time = date('g:i a' - 6, strtotime($time_date_data));

推荐答案

$meeting_time = date('g:i a', strtotime($time_date_data) - 60 * 60 * 6);

字符串时间(strtotime)返回一个以秒为单位的Unix时间戳(从Epoch开始),因此您可以简单地减去21600秒,然后再将其转换回指定的日期格式.

String-to-time (strtotime) returns a Unix Time Stamp which is in seconds (since Epoch), so you can simply subtract the 21600 seconds, before converting it back to the specified date format.

这篇关于从日期减去6小时('g:i a',strtotime($ time_date_data));的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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