开发者

windows version of setTimestamp

I have a php script that runs on unix but I need it to run on windows.

setTimestamp is unix only and I need the windows equivalent.

http://php.net/manual/en/datetime.settimestamp.php

Example:

foreach($config['feeds'] as $feed){
    // in case we didn't save a last checked date, set it 开发者_如何学Goto sometime in the 70's
    $last_date = new DateTime();
    $last_date->setTimestamp(0);
    $last_date_save = 0;
    // the feeds are identified in the cache file by the hash of their url.
    $feed_hash = sha1($feed['url']);

    if(isset($stats[$feed_hash]['lastPubDate'])){
        if($config['debug'] > 0) echo "feed had lastpubdate\n";
        $last_date = new DateTime();
        $last_date->setTimestamp($stats[$feed_hash]['lastPubDate']);
    }

}

Any ideas?


Myth:

settimestamp is NOT Unix-Only.

Real Reason:

The reason it is not working is because its availability is (PHP 5 >= 5.3.0) and your Windows machine may have an older version of PHP installed.

Solution:

  1. Insall latest PHP. OR:
  2. You can use the constructor of the class which is available (PHP 5 >= 5.2.0) like this:

    $last_date = new DateTime('@0'); // change construction line like this
    //$last_date->setTimestamp(0); // <-- remove this line


setTimestamp is unix only

Tthis is a misunderstanding. The term "Unix timestamp" is used for the timestamp format that counts the number of seconds since January 1, 1970. It is just a name, not specific to Unix technically, and will work on Windows in the same way without problems.

Wikipedia: Unix Time

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜