system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.i18n system.i18n.gettext system.logging system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers

CTimestamp

system.utils
继承 class CTimestamp
可用自 1.0
版本 $Id$
CTimestamp represents a timestamp.

This class was adapted from the ADOdb Date Library, as part of the ADOdb abstraction library. The original source code was released under both BSD and GNU Lesser GPL library license, with the following copyright notice: Copyright (c) 2000, 2001, 2002, 2003, 2004 John Lim All rights reserved.

PHP native date static functions use integer timestamps for computations. Because of this, dates are restricted to the years 1901-2038 on Unix and 1970-2038 on Windows due to integer overflow for dates beyond those years. This library overcomes these limitations by replacing the native static function's signed integers (normally 32-bits) with PHP floating point numbers (normally 64-bits).

Dates from 100 A.D. to 3000 A.D. and later have been tested. The minimum is 100 A.D. as <100 will invoke the 2 => 4 digit year conversion. The maximum is billions of years in the future, but this is a theoretical limit as the computation of that year would take too long with the current implementation of getTimestamp.

PERFORMANCE For high speed, this library uses the native date static functions where possible, and only switches to PHP code when the dates fall outside the 32-bit signed integer range.

公共方法

隐藏继承的方法

方法描述被定义在
formatDate() Formats a timestamp to a date string. CTimestamp
get4DigitYear() Returns 4-digit representation of the year. CTimestamp
getDate() Returns the getdate() array. CTimestamp
getDayofWeek() Gets day of week, 0 = Sunday,... 6=Saturday. CTimestamp
getGMTDiff() CTimestamp
getTimestamp() Generates a timestamp. CTimestamp
isLeapYear() Checks for leap year, returns true if it is. No 2-digit year check. Also CTimestamp
isValidDate() Checks to see if the year, month, day are valid combination. CTimestamp
isValidTime() Checks to see if the hour, minute and second are valid. CTimestamp

受保护的方法

隐藏继承的方法

方法描述被定义在
digitCheck() Fix 2-digit years. Works for any century. CTimestamp

方法详情

digitCheck() 方法
protected static integer digitCheck(integer $y)
$y integer year
{return} integer change two digit year into multiple digits

Fix 2-digit years. Works for any century. Assumes that if 2-digit is more than 30 years in future, then previous century.

formatDate() 方法
public static string formatDate(string $fmt, integer $d=false, boolean $is_gmt=false)
$fmt string format pattern
$d integer timestamp
$is_gmt boolean whether this is a GMT timestamp
{return} string formatted date based on timestamp $d

Formats a timestamp to a date string.

get4DigitYear() 方法
public static integer get4DigitYear(integer $y)
$y integer year
{return} integer 4-digit representation of the year

Returns 4-digit representation of the year.

getDate() 方法
public static array getDate(integer $d=false, boolean $fast=false, boolean $gmt=false)
$d integer original date timestamp. False to use the current timestamp.
$fast boolean false to compute the day of the week, default is true
$gmt boolean true to calculate the GMT dates
{return} array an array with date info.

Returns the getdate() array.

getDayofWeek() 方法
public static integer getDayofWeek(integer $year, integer $month, integer $day)
$year integer year
$month integer month
$day integer day
{return} integer day of week

Gets day of week, 0 = Sunday,... 6=Saturday. Algorithm from PEAR::Date_Calc

getGMTDiff() 方法
public static integer getGMTDiff()
{return} integer get local time zone offset from GMT

getTimestamp() 方法
public static integer|float getTimestamp(integer $hr, integer $min, integer $sec, integer $mon=false, integer $day=false, integer $year=false, boolean $is_gmt=false)
$hr integer hour
$min integer minute
$sec integer second
$mon integer month
$day integer day
$year integer year
$is_gmt boolean whether this is GMT time
{return} integer|float a timestamp given a local time. Originally by jackbbs.

Generates a timestamp. Not a very fast algorithm - O(n) operation. Could be optimized to O(1).

isLeapYear() 方法
public static boolean isLeapYear(integer $year)
$year integer year to check
{return} boolean true if is leap year

Checks for leap year, returns true if it is. No 2-digit year check. Also handles julian calendar correctly.

isValidDate() 方法
public static boolean isValidDate(integer $y, integer $m, integer $d)
$y integer year
$m integer month
$d integer day
{return} boolean true if valid date, semantic check only.

Checks to see if the year, month, day are valid combination.

isValidTime() 方法 (自版本 v1.0.5 可用)
public static boolean isValidTime(integer $h, integer $m, integer $s, boolean $hs24=true)
$h integer hour
$m integer minute
$s integer second
$hs24 boolean whether the hours should be 0 through 23 (default) or 1 through 12.
{return} boolean true if valid date, semantic check only.

Checks to see if the hour, minute and second are valid.