timezone_open()函数是PHP中的一个内置函数,用于创建新的DateTimeZone对象。timezone_open()函数接受时区作为参数,并在成功时返回DateTimeZone对象,失败时返回False。
null
语法:
timezone_open( $timezone )
参数: 此函数接受单个参数 $timezone 这是强制性的。它指定要创建的新DateTimeZone对象的时区。
返回值: 成功时返回DateTimeZone对象,失败时返回False。
例外情况: 作为参数传递的时区必须是PHP中支持的时区,否则可能会导致不正确的结果。
下面的程序演示了PHP中的timezone_open()函数:
项目1:
<?php // Creating a new DateTimeZone object $timezone = timezone_open( "America/Chicago" ); echo ( "The new DateTimeZone object created is " . timezone_name_get( $timezone )); ?> |
输出:
The new DateTimeZone object created is America/Chicago
项目2:
<?php // Array of timezones $timezones = array ( 'Europe/London' , 'Asia/Kolkata' ); foreach ( $timezones as $tz ) { $name = timezone_open( $tz ); echo ( "The new DateTimeZone object created is " . timezone_name_get( $name ). "<br>" ); } ?> |
输出:
The new DateTimeZone object created is Europe/LondonThe new DateTimeZone object created is Asia/Kolkata
注: timezone_open()函数给出警告,因为传递的时区不是受支持/有效的时区。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END