dongpao1926 2011-12-22 16:07
浏览 38
已采纳

PHP date()可靠性

I am building a package that heavily relies on the current week number of the year as well as the forthcoming 4 or 5 week numbers. I know that sounds kind of confusing but lets say this week amounts to the 51st one of the year. The next 4 week numbers would be:

  1. 52
  2. 1
  3. 2
  4. 3

My Question:

How reliable is PHP's date() function? The library isn't very well documented and the comments underneath make me a little nervous about using it. I am using the following to get the current week number:

echo $weekNumber = date("W");

Is that a reliable way of working with dates? Any recommendations? I am not very good with dates and times and the sheer size of the various functions available in PHP's native library has left me very confused (time(), strtotime(), date() etc).

  • 写回答

2条回答 默认 最新

  • doumao6048 2011-12-22 16:13
    关注

    I've just done a quick test with the following code:

    echo date('W', strtotime('2011/12/31')) . '<br>';
    echo date('W', strtotime('2011/12/31 +1 week')) . '<br>';
    echo date('W', strtotime('2011/12/31 +2 week')) . '<br>';
    echo date('W', strtotime('2011/12/31 +3 week')) . '<br>';
    

    Here we start with the 31st Dec 2011 (last day this year), then we print 3 more W weeks, which gives this output:

    52
    01
    02
    03
    04
    

    Which does exactly what you want. If PHP's date() function didn't work properly, it would have either been removed (bad!), or rewritten until it did work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图