选择语言 :

Core_Date

日期处理类

常量
Date::YEAR integer 31556926
Date::MONTH integer 2629744
Date::WEEK integer 604800
Date::DAY integer 86400
Date::HOUR integer 3600
Date::MINUTE integer 60
Date::MONTHS_LONG string(2) "%B"
Date::MONTHS_SHORT string(2) "%b"

API - Core_Date

  • Date::$timestamp_format - Default timestamp format for formatted_time
  • Date::$timezone - Timezone for formatted_time
  • Date::offset - Returns the offset (in seconds) between two time zones. Use this to
  • Date::seconds - Number of seconds in a minute, incrementing by a step. Typically used as
  • Date::minutes - Number of minutes in an hour, incrementing by a step. Typically used as
  • Date::hours - Number of hours in a day. Typically used as a shortcut for generating a
  • Date::ampm - Returns AM or PM, based on a given hour (in 24 hour format).
  • Date::adjust - Adjusts a non-24-hour number into a 24-hour number.
  • Date::days - Number of days in a given month and year. Typically used as a shortcut
  • Date::months - Number of months in a year. Typically used as a shortcut for generating
  • Date::years - Returns an array of years between a starting and ending year. By default,
  • Date::span - Returns time difference between two timestamps, in human readable format.
  • Date::fuzzy_span - Returns the difference between a time and now in a "fuzzy" way.
  • Date::unix2dos - Converts a UNIX timestamp to DOS format. There are very few cases where
  • Date::dos2unix - Converts a DOS timestamp to UNIX format.There are very few cases where
  • Date::formatted_time - Returns a date/time string with the specified timestamp format
author
呼吸二氧化碳 jonwang@myqee.com
category
MyQEE
package
System
subpackage
Core
copyright
Copyright © 2008-2013 myqee.com
license
http://www.myqee.com/license.html

Date::offset( $remote , $local = null, $now = null)

Returns the offset (in seconds) between two time zones. Use this to display dates to users in different time zones.

$seconds = Date::offset('America/Chicago', 'GMT');

A list of time zones that PHP supports can be found at

http://php.net/timezones.

参数列表

参数 类型 描述 默认值
$remote string Timezone that to find the offset of
$local string Timezone used as the baseline null
$now mixed UNIX timestamp or date string null
返回值
  • integer

Date::seconds( $step = 1, $start = 0, $end = 60)

Number of seconds in a minute, incrementing by a step. Typically used as a shortcut for generating a list that can used in a form.

$seconds = Date::seconds(); // 01, 02, 03, ..., 58, 59, 60

参数列表

参数 类型 描述 默认值
$step integer Amount to increment each step by, 1 to 30 integer 1
$start integer Start value integer 0
$end integer End value integer 60
返回值
  • array A mirrored (foo => foo) array from 1-60.

Date::minutes( $step = 5)

Number of minutes in an hour, incrementing by a step. Typically used as a shortcut for generating a list that can be used in a form.

$minutes = Date::minutes(); // 05, 10, 15, ..., 50, 55, 60

参数列表

参数 类型 描述 默认值
$step integer Amount to increment each step by, 1 to 30 integer 5
返回值
  • array A mirrored (foo => foo) array from 1-60.

Date::hours( $step = 1, $long = false, $start = null)

Number of hours in a day. Typically used as a shortcut for generating a list that can be used in a form.

$hours = Date::hours(); // 01, 02, 03, ..., 10, 11, 12

参数列表

参数 类型 描述 默认值
$step integer Amount to increment each step by integer 1
$long boolean Use 24-hour time bool false
$start integer The hour to start at null
返回值
  • array A mirrored (foo => foo) array from start-12 or start-23.

Date::ampm( $hour )

Returns AM or PM, based on a given hour (in 24 hour format).

$type = Date::ampm(12); // PM $type = Date::ampm(1); // AM

参数列表

参数 类型 描述 默认值
$hour integer Number of the hour
返回值
  • string

Date::adjust( $hour , $ampm )

Adjusts a non-24-hour number into a 24-hour number.

$hour = Date::adjust(3, 'pm'); // 15

参数列表

参数 类型 描述 默认值
$hour integer Hour to adjust
$ampm string AM or PM
返回值
  • string

Date::days( $month , $year = false)

Number of days in a given month and year. Typically used as a shortcut for generating a list that can be used in a form.

Date::days(4, 2010); // 1, 2, 3, ..., 28, 29, 30

参数列表

参数 类型 描述 默认值
$month integer Number of month
$year integer Number of year to check month, defaults to the current year bool false
返回值
  • array A mirrored (foo => foo) array of the days.

Date::months( $format = null)

Number of months in a year. Typically used as a shortcut for generating a list that can be used in a form.

By default a mirrored array of $month_number => $month_number is returned

Date::months(); // aray(1 => 1, 2 => 2, 3 => 3, ..., 12 => 12)

But you can customise this by passing in either Date::MONTHS_LONG

Date::months(Date::MONTHS_LONG); // array(1 => 'January', 2 => 'February', ..., 12 => 'December')

Or Date::MONTHS_SHORT

Date::months(Date::MONTHS_SHORT); // array(1 => 'Jan', 2 => 'Feb', ..., 12 => 'Dec')

参数列表

参数 类型 描述 默认值
$format string The format to use for months null
返回值
  • array An array of months based on the specified format

Date::years( $start = false, $end = false)

Returns an array of years between a starting and ending year. By default, the the current year - 5 and current year + 5 will be used. Typically used as a shortcut for generating a list that can be used in a form.

$years = Date::years(2000, 2010); // 2000, 2001, ..., 2009, 2010

参数列表

参数 类型 描述 默认值
$start integer Starting year (default is current year - 5) bool false
$end integer Ending year (default is current year + 5) bool false
返回值
  • array

Date::span( $remote , $local = null, $output = 'years,months,weeks,days,hours,minutes,seconds')

Returns time difference between two timestamps, in human readable format. If the second timestamp is not given, the current time will be used. Also consider using [Date::fuzzy_span] when displaying a span.

$span = Date::span(60, 182, 'minutes,seconds'); // array('minutes' => 2, 'seconds' => 2) $span = Date::span(60, 182, 'minutes'); // 2

参数列表

参数 类型 描述 默认值
$remote integer Timestamp to find the span of
$local integer Timestamp to use as the baseline null
$output string Formatting string string(45) "years,months,weeks,days,hours,minutes,seconds"
返回值
  • string when only a single output is requested
  • array associative list of all outputs requested

Date::fuzzy_span( $timestamp , $local_timestamp = null)

Returns the difference between a time and now in a "fuzzy" way. Displaying a fuzzy time instead of a date is usually faster to read and understand.

$span = Date::fuzzy_span(time() - 10); // "moments ago" $span = Date::fuzzy_span(time() + 20); // "in moments"

A second parameter is available to manually set the "local" timestamp, however this parameter shouldn't be needed in normal usage and is only included for unit tests

参数列表

参数 类型 描述 默认值
$timestamp integer "remote" timestamp
$local_timestamp integer "local" timestamp, defaults to time() null
返回值
  • string

Date::unix2dos( $timestamp = false)

Converts a UNIX timestamp to DOS format. There are very few cases where this is needed, but some binary formats use it (eg: zip files.) Converting the other direction is done using {@link Date::dos2unix}.

$dos = Date::unix2dos($unix);

参数列表

参数 类型 描述 默认值
$timestamp integer UNIX timestamp bool false
返回值
  • integer

Date::dos2unix( $timestamp = false)

Converts a DOS timestamp to UNIX format.There are very few cases where this is needed, but some binary formats use it (eg: zip files.) Converting the other direction is done using {@link Date::unix2dos}.

$unix = Date::dos2unix($dos);

参数列表

参数 类型 描述 默认值
$timestamp integer DOS timestamp bool false
返回值
  • integer

Date::formatted_time( $datetime_str = 'now', $timestamp_format = null, $timezone = null)

Returns a date/time string with the specified timestamp format

$time = Date::formatted_time('5 minutes ago');

参数列表

参数 类型 描述 默认值
$datetime_str string Datetime_str datetime string string(3) "now"
$timestamp_format string Timestamp_format timestamp format null
$timezone unknown null
返回值
  • string