<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.datetime.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.date-sunset.php',
    1 => 'date_sunset',
    2 => '返回给定的日期与地点的日落时间',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => 'Date/Time 函数',
  ),
  'prev' => 
  array (
    0 => 'function.date-sunrise.php',
    1 => 'date_sunrise',
  ),
  'next' => 
  array (
    0 => 'function.date-time-set.php',
    1 => 'date_time_set',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/datetime/functions/date-sunset.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.date-sunset" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">date_sunset</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">date_sunset</span> &mdash; <span class="dc-title">
   返回给定的日期与地点的日落时间
  </span></p>

 </div>

 <div id="function.date-sunset-refsynopsisdiv">
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">
    该函数自 PHP 8.1.0 起<em>弃用</em>。强烈建议不要依赖此函数。请改用 <span class="function"><a href="function.date-sun-info.php" class="function">date_sun_info()</a></span>。
   </p>
  </div>
 </div>

 <div class="refsect1 description" id="refsect1-function.date-sunset-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="attribute"><a href="class.deprecated.php">#[\Deprecated]</a> </span><br>
   <span class="methodname"><strong>date_sunset</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$timestamp</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$returnFormat</code><span class="initializer"> = <strong><code><a href="datetime.constants.php#constant.sunfuncs-ret-string">SUNFUNCS_RET_STRING</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.float.php" class="type float">float</a></span></span> <code class="parameter">$latitude</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.float.php" class="type float">float</a></span></span> <code class="parameter">$longitude</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.float.php" class="type float">float</a></span></span> <code class="parameter">$zenith</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.float.php" class="type float">float</a></span></span> <code class="parameter">$utcOffset</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.float.php" class="type float">float</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

   <p class="para rdfs-comment">
   <span class="function"><strong>date_sunset()</strong></span> 返回给定的日期（以
   <code class="parameter">timestamp</code> 指定）与地点的日落时间。
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.date-sunset-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">timestamp</code></dt>
     <dd>
      <p class="para">
       返回给定的日期（以
       <code class="parameter">timestamp</code> 指定）的日落时间。
      </p>
     </dd>
    
    
     <dt><code class="parameter">returnFormat</code></dt>
     <dd>
      <p class="para">
       <table class="doctable table">
        <caption><strong><code class="parameter">returnFormat</code> 常量</strong></caption>
        
         <thead>
          <tr>
           <th>常量</th>
           <th>说明</th>
           <th>取值举例</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>SUNFUNCS_RET_STRING</td>
           <td>以 <span class="type"><a href="language.types.string.php" class="type string">string</a></span> 格式返回结果</td>
           <td>16:46</td>
          </tr>

          <tr>
           <td>SUNFUNCS_RET_DOUBLE</td>
           <td>以 <span class="type"><a href="language.types.float.php" class="type float">float</a></span> 格式返回结果</td>
           <td>16.78243132</td>
          </tr>

          <tr>
           <td>SUNFUNCS_RET_TIMESTAMP</td>
           <td>以 <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> 格式（时间戳）返回结果</td>
           <td>1095034606</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
    
     <dt><code class="parameter">latitude</code></dt>
     <dd>
      <p class="para">
       默认是指北纬。因此如果要指定南纬，必须传递一个负值。参见：<a href="datetime.configuration.php#ini.date.default-latitude" class="link">date.default_latitude</a>
      </p>
     </dd>
    
    
     <dt><code class="parameter">longitude</code></dt>
     <dd>
      <p class="para">
       默认是指东经。因此如果要指定西经，必须传递一个负值。参见：<a href="datetime.configuration.php#ini.date.default-longitude" class="link">date.default_longitude</a>
      </p>
     </dd>
    
    
     <dt><code class="parameter">zenith</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">zenith</code> is the angle between the center of the sun
       and a line perpendicular to earth&#039;s surface. It defaults to
       <a href="datetime.configuration.php#ini.date.sunrise-zenith" class="link">date.sunrise_zenith</a>
       <table class="doctable table">
        <caption><strong>Common <code class="parameter">zenith</code> angles</strong></caption>
        
         <thead>
          <tr>
           <th>Angle</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>90°50&#039;</td>
           <td>Sunrise: the point where the sun becomes visible.</td>
          </tr>

          <tr>
           <td>96°</td>
           <td>Civil twilight: conventionally used to signify the start of dawn.</td>
          </tr>

          <tr>
           <td>102°</td>
           <td>Nautical twilight: the point at which the horizon starts being visible at sea.</td>
          </tr>

          <tr>
           <td>108°</td>
           <td>Astronomical twilight: the point at which the sun starts being the source of any illumination.</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
    
     <dt><code class="parameter">utcOffset</code></dt>
     <dd>
      <p class="para">
       单位是小时。
       The <code class="parameter">utcOffset</code> is ignored, if
       <code class="parameter">returnFormat</code> is
       <strong><code><a href="datetime.constants.php#constant.sunfuncs-ret-timestamp">SUNFUNCS_RET_TIMESTAMP</a></code></strong>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.date-sunset-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   用指定的格式 <code class="parameter">returnFormat</code> 返回日落时间， 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
   One potential reason for failure is that the
   sun does not rise at all, which happens inside the polar circles for part of
   the year.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.date-sunset-errors">
  <h3 class="title">错误／异常</h3>
   
   <p class="para">
在每次调用日期/时间函数时，如果时区无效则会引发 <strong><code><a href="errorfunc.constants.php#constant.e-notice">E_NOTICE</a></code></strong> 错误。参见
<span class="function"><a href="function.date-default-timezone-set.php" class="function">date_default_timezone_set()</a></span>。</p>
 
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.date-sunset-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.1.0</td>
       <td>
        此函数已弃用，请改用 <span class="function"><a href="function.date-sun-info.php" class="function">date_sun_info()</a></span>。
       </td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        <code class="parameter">latitude</code>, <code class="parameter">longitude</code>,
        <code class="parameter">zenith</code> and <code class="parameter">utcOffset</code> are nullable now.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.date-sunset-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>date_sunset()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/* calculate the sunset time for Lisbon, Portugal<br />Latitude: 38.4 North<br />Longitude: 9 West<br />Zenith ~= 90<br />offset: +1 GMT<br />*/<br /><br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"D M d Y"</span><span style="color: #007700">). </span><span style="color: #DD0000">', sunset time : ' </span><span style="color: #007700">.</span><span style="color: #0000BB">date_sunset</span><span style="color: #007700">(</span><span style="color: #0000BB">time</span><span style="color: #007700">(), </span><span style="color: #0000BB">SUNFUNCS_RET_STRING</span><span style="color: #007700">, </span><span style="color: #0000BB">38.4</span><span style="color: #007700">, -</span><span style="color: #0000BB">9</span><span style="color: #007700">, </span><span style="color: #0000BB">90</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Deprecated: Constant SUNFUNCS_RET_STRING is deprecated in script on line 10
Deprecated: Function date_sunset() is deprecated since 8.1, use date_sun_info() instead in script on line 10
Mon Dec 20 2004, sunset time : 18:13</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>示例 #2 No sunrise</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$solstice </span><span style="color: #007700">= </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">'2017-12-21'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">date_sunset</span><span style="color: #007700">(</span><span style="color: #0000BB">$solstice</span><span style="color: #007700">, </span><span style="color: #0000BB">SUNFUNCS_RET_STRING</span><span style="color: #007700">, </span><span style="color: #0000BB">69.245833</span><span style="color: #007700">, -</span><span style="color: #0000BB">53.537222</span><span style="color: #007700">));</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例会输出：</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Deprecated: Constant SUNFUNCS_RET_STRING is deprecated in script on line 3
Deprecated: Function date_sunset() is deprecated since 8.1, use date_sun_info() instead in script on line 3
bool(false)</pre>
</div>
    </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.date-sunset-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.date-sun-info.php" class="function" rel="rdfs-seeAlso">date_sun_info()</a> - Returns an array with information about sunset/sunrise and twilight begin/end</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>