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);
}
?>
Дата и час
- Въведение
- Инсталиране/Конфигуриране
- Предварително-дефинирани константи
- Списък на поддържаните часови зони
- Функции за дата и час
- checkdate — Проверява Грегорианска дата
- date_add — Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object
- date_create — Returns new DateTime object
- date_date_set — Sets the date
- 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_format — Returns date formatted according to given format
- date_isodate_set — Sets the ISO date
- date_modify — Alters the timestamp
- date_offset_get — Returns the daylight saving time offset
- date_parse — Returns associative array with detailed info about given date
- date_sub — Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object
- 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 — Sets the time
- date_timezone_get — Return time zone relative to given DateTime
- date_timezone_set — Sets the time zone for the DateTime object
- date — Форматира местно време/дата
- getdate — Взима информация за датата и часа
- gettimeofday — Взима текущо време
- gmdate — Форматира грийнуички (GMT/UTC) дата и час
- gmmktime — Взима Unix времеви отпечатък за GMT дата
- gmstrftime — Форматира GMT/UTC време и дата според локала
- idate — Форматира местно време и дата като цяло число
- localtime — Взима местното време
- microtime — Връща текущия Unix времеви отпечатък с микросекунди
- mktime — Взима Unix времеви отпечатък за дата
- strftime — Форматира местно време и дата съгласно локала
- strptime — Parse a time/date generated with strftime
- strtotime — Прави разбор (parse) на каквото и да е английско описание за час и дата в Unix времеви отпечатък (timestamp)
- time — Връща текущия Unix времеви отпечатък
- timezone_abbreviations_list — Returns associative array containing dst, offset and the timezone name
- timezone_identifiers_list — Returns numerically index array with all timezone identifiers
- timezone_name_from_abbr — Returns the timezone name from abbrevation
- timezone_name_get — Returns the name of the timezone
- timezone_offset_get — Returns the timezone offset from GMT
- timezone_open — Returns new DateTimeZone object
- timezone_transitions_get — Returns all transitions for the timezone
Дата и час
zoe at monkeehouse dot com
24-Oct-2008 03:52
24-Oct-2008 03:52
JonathanCross.com
25-Jul-2008 01:13
25-Jul-2008 01: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>
