dongzituo5530 2013-09-05 11:45
浏览 18

php计算时间段大小

I need to implement a kind-of advanced time processing feature and I get lost in dozens of PHP's time functions. I've got a TimeUnit class that represents time unit, which is a tuple: from, to and period type, where period_type is month, week or day. Example timeunit is: from: 1st January 2013, to: 28th February 2013, period type: month - which represents two months. 01.01.2013-28.02.2013-month is not the same as 01.01.2013-28.02.2013-day - the latter one is segmented by days and has 59 elements in fact (31 days + 28 days), whereas the former one has 2 elements (just two months).

I need to implement the following: I dump the TimeUnit into the day-scale period type (either from months or from weeks). I need to return sequence of segment sizes, which is a list of sizes. For example I've got 3 weeks TimeUnit and I dump it to days, so I expect to have 7,7,7. If I have 4 months (Jun, Jul, Aug, Sep) I'll get (30,31,31,30).

So far I'm using DateInterval, but it seems there'll be quite a lot of code (different for weeks and different for months) and maybe someone here has a better solution, maybe a built-in PHP function for that?

  • 写回答

1条回答 默认 最新

  • dousheyan0375 2013-09-05 11:48
    关注

    Yep, this sounds like a job for the DateInterval class. I'm not fully sure about your exact requirements (you should show some code), but if the DateInterval class will not do the job completely then you may extend or decorate it.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法