如何节省时间http://time.is/New_York使用PHP


How to scrape time from http://time.is/New_York using PHP?

我对PHP没有任何了解,但我的抓取时间http://time.is/New_York.

我用过这个代码:

<?php
$contents = file_get_contents('http://time.is/New_York');
preg_match('/<div id="twd'd+" [^>]*>([^<]+)<'/div>/im', $contents, $matches);
$title = $matches[0];
print_r($title);
?>
$page = file_get_contents("http://time.is/New_York");
$pattern = '#id="twd">(.*)<#U';
preg_match_all($pattern, $page, $matches); 
echo $matches[1][0];

为什么要"刮"其他网站的时间?您可以在PHP中获取任何时区的日期和时间:

$dt = new DateTime('now', new DateTimezone('America/New_York'));
echo $dt->format('l, F j, Y, 'w'e'e'k W'); # Friday, November 29, 2013, week 48

请参阅PHP中可用的其他时区列表。

演示