将PHP日期调整为当年 [英] Adjust a PHP date to the current year
问题描述
我在数据库中有一个PHP日期,例如2011年8月8日.我以strtotime()格式拥有此日期,因此我可以随意显示它.
I have a PHP date in a database, for example 8th August 2011. I have this date in a strtotime() format so I can display it as I please.
我需要将此日期调整为2013年8月8日(本年).最好的方法是什么?到目前为止,我一直在绞尽脑汁,但无济于事.
I need to adjust this date to make it 8th August 2013 (current year). What is the best way of doing this? So far, I've been racking my brains but to no avail.
推荐答案
strtotime( date( 'd M ', $originaleDate ) . date( 'Y' ) );
这将使用原始时间的日期和月份,加上当前年份,并将其转换为新日期.您还可以将要添加的秒数添加到原始时间戳.在2年中,这将是63 113 852秒.
This takes the day and month of the original time, adds the current year, and converts it to the new date. You can also add the amount of seconds you want to add to the original timestamp. For 2 years this would be 63 113 852 seconds.
这篇关于将PHP日期调整为当年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!