We can also get the submitted datetime (e.g. 2009-11-06 07:03:41) using the following:
<?php
$DateOfRequest = date("Y-m-d H:i:s", strtotime($_REQUEST["DateOfRequest"]));
?>
Or another good example of getting DateTime:
<?php
$DateOfRequest = date("Y-m-d H:i:s", mktime($_REQUEST["Hour"],$_REQUEST["Min"],$_REQUEST
["Sec"],$_REQUEST["Month"],$_REQUEST["Day"],$_REQUEST["Year"]));
?>
Data i Czas
- Wstęp
- Instalacja/Konfiguracja
- Stałe predefiniowane
- Lista obsługiwanych stref czasowych
- 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
- Funkcje daty i czasu
- checkdate — Waliduje datę gregoriańską
- date_add — Alias dla DateTime::add
- date_create_from_format — Alias dla DateTime::createFromFormat
- date_create — Returns new DateTime object
- date_date_set — Alias dla 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 — Alias dla DateTime::diff
- date_format — Alias dla DateTime::format
- date_get_last_errors — Alias dla DateTime::getLastErrors
- date_interval_create_from_date_string — Alias dla DateInterval::createFromDateString
- date_interval_format — Alias dla DateInterval::format
- date_isodate_set — Alias dla DateTime::setISODate
- date_modify — Alias dla DateTime::modify
- date_offset_get — Alias dla DateTime::getOffset
- date_parse_from_format — Get info about given date
- date_parse — Returns associative array with detailed info about given date
- date_sub — Alias dla 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 — Alias dla DateTime::setTime
- date_timestamp_get — Alias dla DateTime::getTimestamp
- date_timestamp_set — Alias dla DateTime::setTimestamp
- date_timezone_get — Alias dla DateTime::getTimezone
- date_timezone_set — Alias dla DateTime::setTimezone
- date — Formatuje lokalny czas/datę
- getdate — Pobiera informację o dacie/czasie
- gettimeofday — Pobiera aktualny czas
- gmdate — Formatuje datę/czas dla strefy GMT/UTC
- gmmktime — Ustala uniksowy znacznik czasu dla daty ze strefy GMT
- gmstrftime — Formatuje czas/datę ze strefy GMT/UTC zgodnie z lokalizacją
- idate — Format a local time/date as integer
- localtime — Pobiera czas lokalny
- microtime — Zwraca aktualny uniksowy znacznik czasu z mikrosekundami
- mktime — Oblicza uniksowy znacznik czasu dla podanej daty
- strftime — Formatuje lokalną datę/czas zgodnie z lokalizacją
- strptime — Parse a time/date generated with strftime
- strtotime — Parsuje większość angielskich tekstowych opisów daty i czasu do uniksowego znacznika czasu
- time — Zwraca aktualny uniksowy znacznik czasu
- timezone_abbreviations_list — Alias dla DateTimeZone::listAbbreviations
- timezone_identifiers_list — Alias dla DateTimeZone::listIdentifiers
- timezone_location_get — Alias dla DateTimeZone::getLocation
- timezone_name_from_abbr — Returns the timezone name from abbreviation
- timezone_name_get — Alias dla DateTimeZone::getName
- timezone_offset_get — Alias dla DateTimeZone::getOffset
- timezone_open — Returns new DateTimeZone object
- timezone_transitions_get — Alias dla DateTimeZone::getTransitions
- timezone_version_get — Gets the version of the timezonedb
data/czas
kapoor_rajiv at hotmail dot com
12-Oct-2009 11:59
12-Oct-2009 11:59
zoe at monkeehouse dot com
24-Oct-2008 10:52
24-Oct-2008 10:52
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);
}
?>
