A very verbose loop. The construct function for the DateTime class isn't working properly for me but this works.
<?php
$date = "2011/03/20";
$date = explode("/", $date);
$time = "07:16:17";
$time = explode(":", $time);
$tz_string = "America/Los_Angeles"; // Use one from list of TZ names http://php.net/manual/en/timezones.php
$tz_object = new DateTimeZone($tz_string);
$datetime = new DateTime();
$datetime->setTimezone($tz_object);
$datetime->setDate($date[0], $date[1], $date[2]);
$datetime->setTime($time[0], $time[1], $time[2]);
print $datetime->format('Y/m/d H:i:s'); // Prints "2011/03/20 07:16:17"
?>
Tarih ve Zaman
- Giriş
- Yapılandırma/Kurulum
- Öntanımlı Sabitler
- Desteklenen Zaman Dilimlerinin Listesi
- Supported Date and Time Formats
- DateTime — DateTime sınıfı
- 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 timezone 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 — DateTimeZone sınıfı
- DateTimeZone::__construct — Yeni bir DateTimeZone nesnesi oluşturur
- DateTimeZone::getLocation — Zaman dilimi konum bilgisini döndürür
- DateTimeZone::getName — Zaman diliminin adını döndürür
- 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 — DateInterval sınıfı
- DateInterval::__construct — Yeni bir DateInterval nesnesi oluşturur
- DateInterval::createFromDateString — Dizgenin göreli kısımlarından bir DateInterval nesnesi döndürür
- DateInterval::format — Zaman aralığını biçimler
- DatePeriod — DatePeriod sınıfı
- DatePeriod::__construct — Yeni bir DatePeriod nesnesi oluşturur
- Tarih ve Zaman İşlevleri
- checkdate — Miladi tarihi doğrular
- date_add — DateTime::add işlevinin takma adıdır
- date_create_from_format — DateTime::createFromFormat işlevinin takma adıdır
- date_create — DateTime::__construct için bir takma ad
- date_date_set — DateTime::setDate işlevinin takma adıdır
- date_default_timezone_get — Betik içerisindeki tüm tarih/zaman işlevleri tarafından kullanılan öntanımlı zaman dilimini getirir
- date_default_timezone_set — Betik içerisindeki tüm tarih/zaman işlevleri tarafından kullanılan öntanımlı zaman dilimini ayarlar
- date_diff — DateTime::diff işlevinin takma adıdır
- date_format — DateTime::format işlevinin takma adıdır
- date_get_last_errors — DateTime::getLastErrors işlevinin takma adıdır
- date_interval_create_from_date_string — DateInterval::createFromDateString işlevinin takma adıdır
- date_interval_format — DateInterval::format işlevinin takma adıdır
- date_isodate_set — DateTime::setISODate işlevinin takma adıdır
- date_modify — DateTime::modify işlevinin takma adıdır
- date_offset_get — DateTime::getOffset işlevinin takma adıdır
- date_parse_from_format — Get info about given date formatted according to the specified format
- date_parse — Verilen tarih hakkındaki ayrıntılı bilgiyi ilişkisel dizi olarak döndürür
- date_sub — DateTime::sub işlevinin takma adıdır
- date_sun_info — Güneşin doğuşu/batışı ve alacakaranlık başlangıcı/sonu hakkında bilgi içeren bir dizi döndürür
- date_sunrise — Belirtilen gün ve konum için şafak zamanını döndürür
- date_sunset — Verilen gün ve konum için günbatımı zamanını döndürür
- date_time_set — DateTime::setTime işlevinin takma adıdır
- date_timestamp_get — DateTime::getTimestamp işlevinin takma adıdır
- date_timestamp_set — DateTime::setTimestamp işlevinin takma adıdır
- date_timezone_get — DateTime::getTimezone işlevinin takma adıdır
- date_timezone_set — DateTime::setTimezone işlevinin takma adıdır
- date — Yerel tarihi/saati biçimlendirir
- getdate — Tarih/zaman bilgisi getirir
- gettimeofday — Geçerli zamanı getirir
- gmdate — Bir tarih/saati GMT/UTC tarih/saati olarak biçemler
- gmmktime — Bir GMT tarihi için Unix zaman damgasını döndürür
- gmstrftime — Yerel ayarlara göre tarih ve saati, GMT/UTC türüne çevirir
- idate — Yerel zamanı/tarihi tamsayı olarak biçimlendirir
- localtime — Yerel zamanı getirir
- microtime — Geçerli Unix zaman damgasını mikrosaniye olarak döndürür
- mktime — Bir tarih için Unix zaman damgasını döndürür
- strftime — Format a local time/date according to locale settings
- strptime — strftime işleviyle üretilen zaman ve tarihleri çözümler
- strtotime — Parse about any English textual datetime description into a Unix timestamp
- time — Geçerli Unix zaman damgasını döndürür
- timezone_abbreviations_list — DateTimeZone::listAbbreviations işlevinin takma adıdır
- timezone_identifiers_list — DateTimeZone::listIdentifiers işlevinin takma adıdır
- timezone_location_get — DateTimeZone::getLocation işlevinin takma adıdır
- timezone_name_from_abbr — Kısaltmasından, zaman diliminin adını döndürür
- timezone_name_get — DateTimeZone::getName işlevinin takma adıdır
- timezone_offset_get — DateTimeZone::getOffset işlevinin takma adıdır
- timezone_open — DateTimeZone::__construct için takma ad
- timezone_transitions_get — DateTimeZone::getTransitions işlevinin takma adıdır
- timezone_version_get — Gets the version of the timezonedb
rjstatic
20-Mar-2011 10:44
Moo0z0r
21-Jun-2010 11:58
I think it's important to mention with the DateTime class that if you're trying to create a system that should store UNIX timestamps in UTC/GMT, and then convert them to a desired custom time-zone when they need to be displayed, using the following code is a good idea:
<?php
date_default_timezone_set('UTC');
?>
Even if you use something like:
<?php
$date->setTimezone( new DateTimeZone('UTC') );
?>
... before you store the value, it doesn't seem to work because PHP is already trying to convert it to the default timezone.
kapoor_rajiv at hotmail dot com
12-Oct-2009 04:59
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"]));
?>
zoe at monkeehouse dot com
24-Oct-2008 03: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);
}
?>
