简体   繁体   中英

date default timezone set problem

I'm using the function

$data=date_default_timezone_set("Ymd");

and I'm getting the date like 0000-00-00 in my table. Can any one help me ?

date_default_timezone_set sets the default timezone and takes time zone identifier(eg "EST" or "EST5EDT"). After time zone is set you can use date function to format datetime value.

date_default_timezone_set("GMT"); // timezone you want to use if you don't want the OS default timezone
$dt = date("Y-m-d");

Do you realize that you are providing a date format, not time zone? Proper argument would be in example "Europe/Prague", what you probably want is date() function

date_default_timezone_set receives a timezone identifier, not a date formatter.

You probably want something like date("Ymd") .

date-default-timezone-set is used for setting a deafult timezone (like "Europe/Moscow"), not for setting date format. You might need to use "date('Ym-d');"

date_default_timezone_set() is used to set the default timezone used by date and time functions.

Calling the function as $data=date_default_timezone_set("Ymd") is wrong for two reasons:

  • The return value of the function is TRUE when the passed parameter is a valid timezone identifier, and FALSE when it's not a valid identifier.
  • The identifier you are using is not valid; it should be something like 'America/New_York' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM