Ejemplo n.º 1
0
function format_time($time_str)
{
    return gm_date(__strtotime($time_str));
}
Ejemplo n.º 2
0
2011-03-25
huanle0610@huanle0610-laptop:~/桌面\$ ./phpDate.php 2011-03-27 100days
2011-07-05
---------------------------------------------------------------------


EOT;
    die($useage);
}
$format = "Y-m-d";
if (validstring($argv[1])) {
    if ($argc == 3 && !validstring($argv[2])) {
        echo date($format, strtotime($argv[2], __strtotime($argv[1])));
    } else {
        $datetime1 = new DateTime(__strtotime($argv[1], true));
        $datetime2 = new DateTime(isset($argv[2]) ? __strtotime($argv[2], true) : null);
        $interval = $datetime2->diff($datetime1);
        echo $interval->format('%R%a days');
    }
} else {
    echo date($format, strtotime($argv[1]));
}
echo "\n";
function __strtotime($datastring, $returnstring = False)
{
    preg_match_all('/^(\\d{2,4})([^\\d]+)(\\d{1,2})\\2(\\d{1,2})$/', $datastring, $t);
    if ($t[1] && $t[3] && $t[4]) {
        if ($returnstring) {
            return $t[1][0] . '-' . $t[3][0] . '-' . $t[4][0];
        } else {
            return mktime(0, 0, 0, $t[3][0], $t[4][0], $t[1][0]);
Ejemplo n.º 3
0
 $new_oneboxs = array();
 foreach ($oneboxs as $onebox) {
     $url = $onebox['url'];
     if (empty($url)) {
         continue;
     }
     $res_obj = get_onebox_url($url);
     if (!isset($onebox['time'])) {
         $onebox['time'] = gm_date(time());
     }
     $ctime_str = @$onebox['ctime'];
     if (empty($ctime_str)) {
         $ctime_str = $onebox['time'];
     }
     $new_ctime = __strtotime($res_obj['create_time']);
     $ori_ctime = __strtotime($ctime_str);
     $ctime = gm_date(min($new_ctime, $ori_ctime));
     $new_onebox = array();
     $new_onebox['title'] = $res_obj['title'];
     $new_onebox['desc'] = $res_obj['description'];
     $new_onebox['image'] = $res_obj['image'];
     $new_onebox['url'] = $res_obj['ori_url'];
     $new_onebox['id'] = $res_obj['ID'];
     $new_onebox['time'] = $res_obj['update_time'];
     $new_onebox['ctime'] = $ctime;
     $new_oneboxs[] = $new_onebox;
     $same_onebox = true;
     foreach ($new_onebox as $key => $val) {
         if ($val !== @$onebox[$key]) {
             $same_onebox = false;
             break;