6个月前:strtotime("-6 months");
2年:strtotime("+2 years");
- 6 months ago:
strtotime("-6 months");
- 2 years:
strtotime("+2 years");
这些将返回Unix时间戳.因此,您可能需要将结果放入date()
或localtime()
或gmtime()
.
These will return Unix timestamps. So you might want to put the result into date()
or localtime()
or gmtime()
.
请不要尝试将time()
减去6个月或增加2年的秒数.这并未考虑夏令时或leap秒等因素,但仍会为您提供以秒为单位的值,这不太可能是您需要的精度.让库函数执行此操作.
Please do not try to subtract 6 months or add 2 years of seconds to time()
. This does not take into account things like daylight saving or leap seconds and still gives you a value in seconds which is unlikely to be the precision you need. Let the library functions do it.
这篇关于PHP中的日期算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!