智能日期显示（把时间显示为n小时n分钟前/后，或昨天、前天、年-月-日后面连着时分秒）
@todo 在\wf\util\DateTime类实现
@param int $time
@param string $ymd 年月日显示格式
@param string $his 时分秒显示格式，空则不显示
@return string
165888
function smartDate($time, $ymd = 'Y-m-d', $his = 'H:i:s') 
	{
		$r = '';
	
		if (abs(time() - $time) < 24*3600) {
			$seconds = time() - $time;
			if($seconds > 0) {
				if ($seconds > 3600) {
					$r .= floor($seconds/3600) . "小时";
				}
				$r .= ceil($seconds%3600/60) . "分钟前";
			} else {
				$seconds =  -$seconds;
				if ($seconds > 3600) {
					$r .= floor($seconds/3600) . "小时";
				}
				$r .=  ceil($seconds%3600/60) . "分钟后";
			}
		} else {
			if (date('Y-m-d', strtotime('-1 day')) == date('Y-m-d', $time)) {
				$r = '昨天';
			} elseif (date('Y-m-d', strtotime('-2 day')) == date('Y-m-d', $time)) {
				$r = '前天';
			} elseif (date('Y-m-d', strtotime('+1 day')) == date('Y-m-d', $time)) {
				$r = '明天';
			} elseif (date('Y-m-d', strtotime('+2 day')) == date('Y-m-d', $time)) {
				$r = '后天';
			} else {
				$r = date($ymd, $time);
			}
	
			$his && $r .= ' ' . date($his);
		}
	
		return $r;
	}
607654
public static function makeDateTime($day, $month, $year, $hour, $min, $sec) {
        return $year ."-". $month ."-". $day ." ". $hour .":". $min .":". $sec;
    }
620181
public function setDateTime($fecha = 'now', $hora = 'now'){
		$ymd = date("ymd",strtotime($fecha)) ;
		$his = date("His",strtotime($hora)) ;
		return "X".$this->cm('FS').$ymd.$this->cm('FS').$his;
	}
645318
public static function createFromDateString($time)
    {
        $interval = parent::createFromDateString($time);
        if ($interval instanceof DateInterval && !($interval instanceof static)) {
            $interval = static::instance($interval);
        }

        return static::instance($interval);
    }
147736
static function relative($time, $alwaysTime = false) {
		$time=self::convert($time, self::PHP);
		$today=date("Ymd");
		if ($time->format("Ymd")==$today) {
			return "dnes v ".$time->format("H.i");
		}
		$time2=clone $time;
		if ($time2->add(new DateInterval("P1D"))->format("Ymd")==$today) {
			return "včera v ".$time->format("H.i");
		}
		$time2=clone $time;
		if ($time2->add(new DateInterval("P2D"))->format("Ymd")==$today) {
			return "předevčírem v ".$time->format("H.i");
		}
		if ($time->format("Y")==date("Y")) {
			return $time->format("j. n.").($alwaysTime?(" v ".$time->format("H.i")):"");
		}
		return $time->format("j. n. Y").($alwaysTime?(" v ".$time->format("H.i")):"");
	}
1167159
public static function ToTimestamp($DateTime = '') {
      if (($TestTime = strtotime($DateTime)) !== FALSE) {
         return $TestTime;
      } elseif (preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})(?:\s{1}(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/', $DateTime, $Matches)) {
         $Year = $Matches[1];
         $Month = $Matches[2];
         $Day = $Matches[3];
         $Hour = ArrayValue(4, $Matches, 0);
         $Minute = ArrayValue(5, $Matches, 0);
         $Second = ArrayValue(6, $Matches, 0);
         return mktime($Hour, $Minute, $Second, $Month, $Day, $Year);
      } elseif (preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})$/', $DateTime, $Matches)) {
         $Year = $Matches[1];
         $Month = $Matches[2];
         $Day = $Matches[3];
         return mktime(0, 0, 0, $Month, $Day, $Year);
      // } elseif ($DateTime == '') {
      //    return time();
      } else {
         return FALSE;
      }
   }
787076
public static function formatStrTime($time, $withSeconds = true)
    {
        // Pad left with 0 in case we get numbers like 123, 12, 122015
        $time = str_pad($time.'', 6, '0', STR_PAD_LEFT);

        $_time = array();

        $_time[] = substr($time, 0, 2);
        $_time[] = substr($time, 2, 2);

        if ($withSeconds) {
            $_seconds = substr($time, 4, 2);
            $_time[] = $_seconds;
        }

        return implode(':', $_time);
    }
74565
static function howLongAgo($datetime)
    {
        $timestamp = strtotime($datetime);
        $seconds = time();

        $time = date('Y', $seconds) - date('Y', $timestamp);
        if ($time > 0)
        {
            if ($time == 1)
            {
                return '去年';
            }
            else
            {
                return $time . '年前';
            }
        }

        $time = date('m', $seconds) - date('m', $timestamp);
        if ($time > 0)
        {
            if ($time == 1)
            {
                return '上月';
            }
            else
            {
                return $time . '个月前';
            }
        }
        $time = date('d', $seconds) - date('d', $timestamp);
        if ($time > 0)
        {
            if ($time == 1)
            {
                return '昨天';
            }
            elseif ($time == 2)
            {
                return '前天';
            }
            else
            {
                return $time . '天前';
            }
        }

        $time = date('H', $seconds) - date('H', $timestamp);
        if ($time >= 1)
        {
            return $time . '小时前';
        }

        $time = date('i', $seconds) - date('i', $timestamp);
        if ($time >= 1)
        {
            return $time . '分钟前';
        }

        $time = date('s', $seconds) - date('s', $timestamp);
        return $time . '秒前';
    }
48389
public static function timeStamp($time)
    {
        $different = time() - $time;

        $seconds = $different;
        $minutes = round($different / 60);
        $hours = round($different / 3600);
        $days = round($different / 86400);
        $weeks = round($different / 604800);
        $months = round($different / 2419200);
        $years = round($different / 29030400);

        //Second
        if ($seconds <= 60) {
            if ($seconds == 1) {
                return "$seconds second ago";
            } else {
                return "$seconds seconds ago";
            }
        }

        //Minutes
        elseif ($minutes <= 60) {
            if ($minutes == 1) {
                return "$minutes minute ago";
            } else {
                return "$minutes minutes ago";
            }
        }

        //Hours
        elseif ($hours <= 24) {
            if ($hours == 1) {
                return "$hours hour ago";
            } else {
                return "$hours hours ago";
            }
        }

        //Days
        elseif ($days <= 7) {
            if ($days = 1) {
                return "$days day ago";
            } else {
                return "$days days ago";
            }
        }

        //Weeks
        elseif ($weeks <= 4) {
            if ($weeks == 1) {
                return "$weeks week ago";
            } else {
                return "$weeks weeks ago";
            }
        }

        //Months
        elseif ($months <= 12) {
            if ($months == 1) {
                return "$months month ago";
            } else {
                return "$months months ago";
            }
        }

        //Years
        else {
            if ($years == 1) {
                return "$years year ago";
            } else {
                return "$years years ago";
            }
        }
    }
340368
public static function getWeekNumberOfMonth($datetime)
    {
        $first_day_of_month = clone $datetime;
        $first_day_of_month->modify('first day of this month');

        return ceil($datetime->format('W') - $first_day_of_month->format('W')) + 1;
    }
465024
protected function makeDosTime($time)
    {
        $timearray = getdate($time);
        if ($timearray['year'] < 1980) {
            $timearray['year']    = 1980;
            $timearray['mon']     = 1;
            $timearray['mday']    = 1;
            $timearray['hours']   = 0;
            $timearray['minutes'] = 0;
            $timearray['seconds'] = 0;
        }
        return (($timearray['year'] - 1980) << 25) |
        ($timearray['mon'] << 21) |
        ($timearray['mday'] << 16) |
        ($timearray['hours'] << 11) |
        ($timearray['minutes'] << 5) |
        ($timearray['seconds'] >> 1);
    }
819670
public function monthly($month = '*', $day = 1, $hour = 0, $minute = 0)
    {
        if (\is_string($hour)) {
            $parts = explode(':', $hour);
            $hour = $parts[0];
            $minute = $parts[1] ?? '0';
        }
        $c = $this->validateCronSequence($minute, $hour, $day, $month);

        return $this->at("{$c['minute']} {$c['hour']} {$c['day']} {$c['month']} *");
    }
677607
public static function date($format = "Y-m-d H:i:s", $time = null)
    {
        $time = ($time !== null ? $time : time());

        if (!is_numeric($time)) {
            $time = static::toUnix($time);
        }

        return date($format, $time);
    }
702575
public static function getPurMonth($date)
    {
        $time = strtotime($date);
        $firstDay = date('Y-m-01', strtotime(date('Y', $time) . '-' . (date('m', $time) - 1) . '-01'));
        $lastDay = date('Y-m-d', strtotime("$firstDay +1 month -1 day"));

        return array($firstDay, $lastDay);
    }
1147796
public function ymdToJd($year, $month, $day)
    {
        return
            $this->yToJd($year) +
            self::$CUMULATIVE_DAYS[$this->isLeapYear($year)][$this->yearType($year)][$month] +
            $day - 1;
    }
563377
public static function shortTime($time)
    {
        if (self::isTime($time)) {
            $str = self::dateTimeToTimeStamp($time);
            $string = date("H:i", $str);
            return $string;
        } else {
            return null;
        }
    }
1285525
function yyyymmddDateFromMonthDayYearDate(monthDayYearDate) {
	var yyyy = monthDayYearDate.split(',')[1].trim();
	var dd = monthDayYearDate.split(' ')[1].split(',')[0];
	var mm = '';
	switch (monthDayYearDate.split(' ')[0]) {
		case 'January': 
			mm = '01';
			break;
		case 'February':
			mm = '02';
			break;
		case 'March':
			mm = '03';
			break;
		case 'April':
			mm = '04';
			break;
		case 'May':
			mm = '05';
			break;
		case 'June':
			mm = '06';
			break;
		case 'July':
			mm = '07';
			break;
		case 'August':
			mm = '08';
			break;
		case 'September':
			mm = '09';
			break;
		case 'October':
			mm = '10';
			break;
		case 'November':
			mm = '11';
			break;
		case 'December':
			mm = '12';
			break;
	}
	return yyyy + '-' + mm + '-' + dd;
}