Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: date_create - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

date_date_set" width="11" height="7"/> <checkdate
Last updated: Thu, 31 May 2007

view this page in

date_create

(PHP 5 >= 5.1.0)

date_create — 新しい DateTime オブジェクトを返す

説明

DateTime date_create ( [string $time [, DateTimeZone $timezone]] )
DateTime DateTime::__construct ( [string $time [, DateTimeZone $timezone]] )

パラメータ

time

strtotime() が理解する形式の文字列。デフォルトは "now" です。

timezone

その時間のタイムゾーン。

返り値

成功した場合に DateTime オブジェクト、失敗した場合に FALSE を返します。



date_date_set" width="11" height="7"/> <checkdate
Last updated: Thu, 31 May 2007
 
add a note add a note User Contributed Notes
date_create
Dok
05-Jul-2007 11:52
If you want to create the DateTime object directly from a timestamp use this

<?
$st
= 1170288000 //  a timestamp
$dt = new DateTime("@$st");
?>

See also: http://bugs.php.net/bug.php?id=40171
artur at jedlinski dot pl
19-Apr-2007 09:47
"String in a format accepted by strtotime()" is not 100% truth - you cannot pass timezone info in the string used as DateTime constructor, while you can do it with strtotime(). It may be a problem if you would like to create a date from GMT time and then display it in your local timezone, for example:

<?php
    $timeZone
= 'Europe/Warsaw'// +2 hours
   
date_default_timezone_set($timeZone);
   
   
$dateSrc = '2007-04-19 12:50 GMT';
   
$dateTime = new DateTime($dateSrc);
   
    echo
'date(): '.date('H:i:s', strtotime($dateSrc));
   
// correct! date(): 14:50:00
   
   
echo 'DateTime::format(): '.$dateTime->format('H:i:s');
   
// INCORRECT! DateTime::format(): 12:50:00
?>

So if you want to convert date between different timezones, you have to create two DateTimeZone objects - one for the input and one for output, like this:

<?php
    $timeZone
= 'Europe/Warsaw'// +2 hours
   
$dateSrc = '2007-04-19 12:50';
   
   
$dateTime = new DateTime($dateSrc, new DateTimeZone('GMT'));
   
$dateTime->setTimeZone(new DateTimeZone($timeZone));
    echo
'DateTime::format(): '.$dateTime->format('H:i:s');
   
// CORRECT! DateTime::format(): 14:50:00
?>

I'm not sure if this is a bug or desired behaviour.
nizar dot jouini at gmail.com
07-Mar-2007 10:05
date_create and other DateTime related functions are included by default only in PHP versions equal and greater than 5.2.

In PHP 5.1.2 this functionality is marked to be experimental and has to be enabled at compile time.

date_date_set" width="11" height="7"/> <checkdate
Last updated: Thu, 31 May 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites