function.timezone-offset-get.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 110 行
HTML
110 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Returns the timezone offset from GMT</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.timezone-name-get.html">timezone_name_get</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.timezone-open.html">timezone_open</a></div> <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.timezone-offset-get" class="refentry"> <div class="refnamediv"> <h1 class="refname">timezone_offset_get</h1> <p class="verinfo">(PHP 5 >= 5.1.0)</p><p class="refpurpose"><span class="refname">timezone_offset_get</span> — <span class="dc-title">Returns the timezone offset from GMT</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><b><b>timezone_offset_get</b></b></span> ( <span class="methodparam"><span class="type"><span class="type DateTimeZone">DateTimeZone</span></span> <tt class="parameter">$object</tt></span> , <span class="methodparam"><span class="type"><span class="type DateTime">DateTime</span></span> <tt class="parameter">$datetime</tt></span> )</div> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><b><b>DateTimeZone::getOffset</b></b></span> ( <span class="methodparam"><span class="type"><span class="type DateTime">DateTime</span></span> <tt class="parameter">$datetime</tt></span> )</div> <p class="para rdfs-comment"> This function returns the offset to GMT for the date/time specified in the <i><tt class="parameter">datetime</tt></i> parameter. The GMT offset is calculated with the timezone information contained in the DateTime object being used. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">object</tt></i></span> <dd> <p class="para"> DateTimeZone object. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">datetime</tt></i></span> <dd> <p class="para"> DateTime that contains the date/time to compute the offset from. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns time zone offset in seconds on success or <b><tt>FALSE</tt></b> on failure. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>timezone_offset_get()</b> examples</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Create two timezone objects, one for Taipei (Taiwan) and one for<br />// Tokyo (Japan)<br /></span><span style="color: #0000BB">$dateTimeZoneTaipei </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">"Asia/Taipei"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dateTimeZoneJapan </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">"Asia/Tokyo"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Create two DateTime objects that will contain the same Unix timestamp, but<br />// have different timezones attached to them.<br /></span><span style="color: #0000BB">$dateTimeTaipei </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">"now"</span><span style="color: #007700">, </span><span style="color: #0000BB">$dateTimeZoneTaipei</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dateTimeJapan </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">"now"</span><span style="color: #007700">, </span><span style="color: #0000BB">$dateTimeZoneJapan</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Calculate the GMT offset for the date/time contained in the $dateTimeTaipei<br />// object, but using the timezone rules as defined for Tokyo<br />// ($dateTimeZoneJapan).<br /></span><span style="color: #0000BB">$timeOffset </span><span style="color: #007700">= </span><span style="color: #0000BB">$dateTimeZoneJapan</span><span style="color: #007700">-></span><span style="color: #0000BB">getOffset</span><span style="color: #007700">(</span><span style="color: #0000BB">$dateTimeTaipei</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Should show int(32400) (for dates after Sat Sep 8 01:00:00 1951 JST).<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$timeOffset</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.timezone-name-get.html">timezone_name_get</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.timezone-open.html">timezone_open</a></div> <div class="up"><a href="ref.datetime.html">Date/Time Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?