在2周内获取php中的日期 [英] Get date in php in 2 weeks

查看:68
本文介绍了在2周内获取php中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$addhr = time() + (1 * 13 * 60 * 60);
$curDateTimeMil= date("Y-m-d G:i:s",$addhr);
echo $curDateTimeMil; 

这将回显 2010-08-27 16:21:31 .

两周后如何获得日期?(9月10日)

How can I get the date after 2 weeks? (sept 10)

推荐答案

$dateInTwoWeeks = strtotime('+2 weeks');

请参见 strtotime() .

更新#1 :是的,这是一种懒惰的方式.但是,我确实相信可能对性能的负面影响可以通过对代码的可读性/理解的积极影响来抵消.如果性能成为问题,则可以切换到本地(基于整数)时间操作(并添加注释).

Update #1: Yes, this is the lazy way to do it. However, I do believe that the possible negative performance impact is countered by the positive effect on readability / understanding of the code. Should performance be an issue, one could switch to native (integer-based) time manipulation (and add comments).

更新#2 :第二个可选参数是参考日期.例如:

Update #2: The optional second argument is the reference date. E.g.:

strtotime('+2 weeks', mktime(0, 0, 0, 2, 8, 1984)); // 8th Feb. 1984 + 2 weeks

这篇关于在2周内获取php中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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