Strange behavior of PHP time math: Why is strtotime() returning negative numbers?

前端 未结 5 915
星月不相逢
星月不相逢 2020-12-12 00:51

I\'m trying to do some very basic time math - basically, given inputs of time and distance, calculate the speed. I chose to use strtotime() to convert the time inputs into s

5条回答
  •  独厮守ぢ
    2020-12-12 01:36

    Try it without the second parameter. That's supposed to be a timestamp for the returned time to be relative to. Giving it 0 means you're asking for a timestamp relative to the Unix epoch.

    In response to your comment:

    It's not documented functionality, but I use strtotime("HH:MM") all the time, and it returns a timestamp relative to the current time. I guess if you want to be sure though, you could do this:

    strtotime("3:15:00",time());
    

提交回复
热议问题