Should you want to convert between HH:MM:SS and plain seconds like in MySQL, these functions should do the trick:
<?php
function time_to_sec($time) {
$hours = substr($time, 0, -6);
$minutes = substr($time, -5, 2);
$seconds = substr($time, -2);
return $hours * 3600 + $minutes * 60 + $seconds;
}
function sec_to_time($seconds) {
$hours = floor($seconds / 3600);
$minutes = floor($seconds % 3600 / 60);
$seconds = $seconds % 60;
return sprintf("%d:%02d:%02d", $hours, $minutes, $seconds);
}
?>
Date and Time
- 소개
- 설치/설정
- 예약 상수
- 지원하는 시간대 목록
- DateTime — The DateTime class
- DateTime::add — Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object
- DateTime::__construct — Returns new DateTime object
- DateTime::createFromFormat — Returns new DateTime object formatted according to the specified format
- DateTime::diff — Returns the difference between two DateTime objects
- DateTime::format — Returns date formatted according to given format
- DateTime::getLastErrors — Returns the warnings and errors
- DateTime::getOffset — Returns the daylight saving time offset
- DateTime::getTimestamp — Gets the Unix timestamp
- DateTime::getTimezone — Return time zone relative to given DateTime
- DateTime::modify — Alters the timestamp
- DateTime::__set_state — The __set_state handler
- DateTime::setDate — Sets the date
- DateTime::setISODate — Sets the ISO date
- DateTime::setTime — Sets the time
- DateTime::setTimestamp — Sets the date and time based on an Unix timestamp
- DateTime::setTimezone — Sets the time zone for the DateTime object
- DateTime::sub — Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object
- DateTime::__wakeup — The __wakeup handler
- DateTimeZone — The DateTimeZone class
- DateTimeZone::__construct — Creates new DateTimeZone object
- DateTimeZone::getLocation — Returns location information for a timezone
- DateTimeZone::getName — Returns the name of the timezone
- DateTimeZone::getOffset — Returns the timezone offset from GMT
- DateTimeZone::getTransitions — Returns all transitions for the timezone
- DateTimeZone::listAbbreviations — Returns associative array containing dst, offset and the timezone name
- DateTimeZone::listIdentifiers — Returns numerically index array with all timezone identifiers
- DateInterval — The DateInterval class
- DateInterval::__construct — Creates new DateInterval object
- DateInterval::createFromDateString — Sets up a DateInterval from the relative parts of the string
- DateInterval::format — Formats the interval
- DatePeriod — The DatePeriod class
- DatePeriod::__construct — Creates new DatePeriod object
- Date/Time 함수 목록
- checkdate — 그레고리력 날짜를 확인합니다
- date_add — 별칭: DateTime::add
- date_create_from_format — 별칭: DateTime::createFromFormat
- date_create — Returns new DateTime object
- date_date_set — 별칭: DateTime::setDate
- date_default_timezone_get — Gets the default timezone used by all date/time functions in a script
- date_default_timezone_set — Sets the default timezone used by all date/time functions in a script
- date_diff — 별칭: DateTime::diff
- date_format — 별칭: DateTime::format
- date_get_last_errors — 별칭: DateTime::getLastErrors
- date_interval_create_from_date_string — 별칭: DateInterval::createFromDateString
- date_interval_format — 별칭: DateInterval::format
- date_isodate_set — 별칭: DateTime::setISODate
- date_modify — 별칭: DateTime::modify
- date_offset_get — 별칭: DateTime::getOffset
- date_parse_from_format — Get info about given date
- date_parse — Returns associative array with detailed info about given date
- date_sub — 별칭: DateTime::sub
- date_sun_info — Returns an array with information about sunset/sunrise and twilight begin/end
- date_sunrise — Returns time of sunrise for a given day and location
- date_sunset — Returns time of sunset for a given day and location
- date_time_set — 별칭: DateTime::setTime
- date_timestamp_get — 별칭: DateTime::getTimestamp
- date_timestamp_set — 별칭: DateTime::setTimestamp
- date_timezone_get — 별칭: DateTime::getTimezone
- date_timezone_set — 별칭: DateTime::setTimezone
- date — 로컬 날짜/시간을 형식화합니다
- getdate — 날짜/시간 정보를 가져온다
- gettimeofday — Get current time
- gmdate — Format a GMT/UTC date/time
- gmmktime — Get Unix timestamp for a GMT date
- gmstrftime — Format a GMT/UTC time/date according to locale settings
- idate — Format a local time/date as integer
- localtime — Get the local time
- microtime — Return current Unix timestamp with microseconds
- mktime — Get Unix timestamp for a date
- strftime — Format a local time/date according to locale settings
- strptime — Parse a time/date generated with strftime
- strtotime — Parse about any English textual datetime description into a Unix timestamp
- time — Return current Unix timestamp
- timezone_abbreviations_list — 별칭: DateTimeZone::listAbbreviations
- timezone_identifiers_list — 별칭: DateTimeZone::listIdentifiers
- timezone_location_get — 별칭: DateTimeZone::getLocation
- timezone_name_from_abbr — Returns the timezone name from abbrevation
- timezone_name_get — 별칭: DateTimeZone::getName
- timezone_offset_get — 별칭: DateTimeZone::getOffset
- timezone_open — Returns new DateTimeZone object
- timezone_transitions_get — 별칭: DateTimeZone::getTransitions
Date/Time
zoe at monkeehouse dot com
25-Oct-2008 01:52
25-Oct-2008 01:52
JonathanCross.com
25-Jul-2008 11:13
25-Jul-2008 11:13
<?php
// A demonstration of the new DateTime class and the
// fact that it fixes dates before 1970 and after 2038.
?>
<h2>PHP 2038 date bug demo (php version <?=phpversion()?>)</h1>
<div style='float:left;margin-right:3em;'>
<h3>OLD Buggy date()</h3>
<?
for ( $i = 1900; $i < 2050; $i++) {
$datep = "$i-01-01";
print " Trying: $datep ... ";
print date("F j, Y", strtotime($datep));
print "<BR>";
}
?></div>
<div style='float:left;'>
<h3>NEW DateTime Class (v 5.2+)</h3><?
for ( $i = 1900; $i < 2050; $i++) {
$datep = "$i-01-01";
$date = new DateTime($datep);
print " Trying: $datep ... ";
print $date->format('F j, Y');
print "<BR>";
}
?></div>
