<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.date.php',
    1 => 'date',
    2 => 'Unixタイムスタンプを書式化する',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => '日付・時刻 関数',
  ),
  'prev' => 
  array (
    0 => 'function.checkdate.php',
    1 => 'checkdate',
  ),
  'next' => 
  array (
    0 => 'function.date-add.php',
    1 => 'date_add',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/datetime/functions/date.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.date" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">date</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">date</span> &mdash; <span class="dc-title">Unixタイムスタンプを書式化する</span></p>

 </div>
  
 <div class="refsect1 description" id="refsect1-function.date-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>date</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$format</code></span>, <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.integer.php" class="type int">int</a></span></span> <code class="parameter">$timestamp</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   指定された引数 <code class="parameter">timestamp</code>
   (Unixタイムスタンプ) を、与えられた
   フォーマット文字列によりフォーマットし、日付文字列を返します。
   タイムスタンプが与えられない場合は、現在の時刻が使われます。
   つまり <code class="parameter">timestamp</code> はオプションであり
   そのデフォルト値は <span class="function"><a href="function.time.php" class="function">time()</a></span> の値です。
  </p>
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">
    Unixタイムスタンプはタイムゾーンを処理しません。
    タイムゾーン情報が付加された日付/時刻の情報を書式化するには、
    <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span> クラスや、
    <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span> を使って下さい。
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.date-parameters">
  <h3 class="title">パラメータ</h3>
  <dl>
   
    <dt><code class="parameter">format</code></dt>
    <dd>
     <p class="para">
      <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span> が受け入れるフォーマット。
     </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <span class="simpara">
        <span class="function"><strong>date()</strong></span> 関数は、マイクロ秒については常に
        <code class="literal">000000</code> を生成します。
        というのも、この関数が受け取るパラメータは int 型だからです。
        一方 <span class="classname"><a href="class.datetimeinterface.php" class="classname">DateTimeInterface</a></span> 型のオブジェクトをマイクロ秒つきで作成した場合は、
        <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span> はマイクロ秒にも対応しています。
       </span>
      </p></blockquote>
    </dd>
   
   
<dt><code class="parameter">timestamp</code></dt><dd><p class="para">
オプションのパラメータ <code class="parameter">timestamp</code> は、
<span class="type"><a href="language.types.integer.php" class="type int">int</a></span> 型の Unix タイムスタンプです。
<code class="parameter">timestamp</code> が指定されなかったり、<strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> だった場合のデフォルト値は、
現在の時刻です。言い換えると、デフォルトは
<span class="function"><a href="function.time.php" class="function">time()</a></span> の返り値となります。
</p></dd>
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.date-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   フォーマットされた日付を表す文字列を返します。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.date-errors">
  <h3 class="title">エラー / 例外</h3>
   
   <p class="para">
すべての日付/時刻関数は、
有効なタイムゾーンが設定されていない場合に <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</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-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.0.0</td>
       <td>
        <code class="parameter">timestamp</code> は、nullable になりました。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.date-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="function"><strong>date()</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 /></span><span style="color: #FF8000">// set the default timezone to use.<br /></span><span style="color: #0000BB">date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'UTC'</span><span style="color: #007700">);<br /><br /><br /></span><span style="color: #FF8000">// Prints something like: Monday<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Prints something like: Monday 8th of August 2005 03:12:46 PM<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l jS \of F Y h:i:s A'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Prints: July 1, 2000 is on a Saturday<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"July 1, 2000 is on a " </span><span style="color: #007700">. </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">, </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">7</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2000</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* use the constants in the format parameter */<br />// prints something like: Wed, 25 Sep 2013 15:28:57 -0700<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_RFC2822</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// prints something like: 2000-07-01T00:00:00+00:00<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_ATOM</span><span style="color: #007700">, </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">7</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2000</span><span style="color: #007700">));</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   前にバックスラッシュを付けてエスケープすることにより、
   フォーマット文字列として認識される文字が展開されることを防止することができます。
   バックスラッシュ付きの文字は既に特別なシーケンスであり、
   バックスラッシュもエスケープすることが必要となる可能性があります。
   <div class="example" id="example-2">
    <p><strong>例2 <span class="function"><strong>date()</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 /></span><span style="color: #FF8000">// Wednesday the 15th のように出力<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l \t\h\e jS'</span><span style="color: #007700">);</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <span class="function"><strong>date()</strong></span> フォーマットのいくつかの例を示します。
   現在の実装で特別な意味がある文字や今後の PHP のバージョンで意味が
   割り付けられるであろう文字については、望ましくない結果を避けるために
   エスケープする必要があることに注意してください。エスケープを
   する際には、改行文字 \n のような文字を回避するために
   シングルクォートを使用してください。
   <div class="example" id="example-3">
    <p><strong>例3 <span class="function"><strong>date()</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 /></span><span style="color: #FF8000">// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the<br />// Mountain Standard Time (MST) Time Zone<br /></span><span style="color: #0000BB">date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">"America/Phoenix"</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"F j, Y, g:i a"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                 </span><span style="color: #FF8000">// March 10, 2001, 5:16 pm<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m.d.y"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                         </span><span style="color: #FF8000">// 03.10.01<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"j, n, Y"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                       </span><span style="color: #FF8000">// 10, 3, 2001<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Ymd"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                           </span><span style="color: #FF8000">// 20010310<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'h-i-s, j-m-y, it is w Day'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;     </span><span style="color: #FF8000">// 05-16-18, 10-03-01, 1631 1618 6 Satpm01<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'\i\t \i\s \t\h\e jS \d\a\y.'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;   </span><span style="color: #FF8000">// it is the 10th day.<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 j G:i:s T Y"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;               </span><span style="color: #FF8000">// Sat Mar 10 17:16:18 MST 2001<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'H:m:s \m \i\s\ \m\o\n\t\h'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;     </span><span style="color: #FF8000">// 17:03:18 m is month<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"H:i:s"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                         </span><span style="color: #FF8000">// 17:16:18<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y-m-d H:i:s"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;                   </span><span style="color: #FF8000">// 2001-03-10 17:16:18 (the MySQL DATETIME format)</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   他の言語で日付をフォーマットする用途には、
   <span class="function"><strong>date()</strong></span> のかわりに
   <span class="methodname"><a href="intldateformatter.format.php" class="methodname">IntlDateFormatter::format()</a></span>
   が使えます。
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.date-notes">
  <h3 class="title">注意</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    日付の文字列表現からタイムスタンプを生成するには、
    <span class="function"><a href="function.strtotime.php" class="function">strtotime()</a></span> が使用できるでしょう。
    さらに、いくつかのデータベースは（MySQL の
    <a href="http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html" class="link external">&raquo;&nbsp;UNIX_TIMESTAMP</a> 関数の
    ような）日付フォーマットからタイムスタンプへの変換関数を有しています。
   </p>
  </p></blockquote>
  <div class="tip"><strong class="tip">ヒント</strong>
   <p class="para">
    <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER['REQUEST_TIME']</a></var>
    によって、リクエスト開始時のタイムスタンプが取得できます。
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.date-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="datetimeimmutable.construct.php" class="methodname" rel="rdfs-seeAlso">DateTimeImmutable::__construct()</a> - 新しい DateTimeImmutable オブジェクトを返す</span></li>
    <li><span class="methodname"><a href="datetime.format.php" class="methodname" rel="rdfs-seeAlso">DateTimeInterface::format()</a> - 指定した書式でフォーマットした日付を返す</span></li>
    <li><span class="function"><a href="function.gmdate.php" class="function" rel="rdfs-seeAlso">gmdate()</a> - GMT/UTC の日付/時刻を書式化する</span></li>
    <li><span class="function"><a href="function.idate.php" class="function" rel="rdfs-seeAlso">idate()</a> - ローカルな時刻/日付の一部を整数として整形する</span></li>
    <li><span class="function"><a href="function.getdate.php" class="function" rel="rdfs-seeAlso">getdate()</a> - 日付/時刻情報を取得する</span></li>
    <li><span class="function"><a href="function.getlastmod.php" class="function" rel="rdfs-seeAlso">getlastmod()</a> - 最終更新時刻を取得する</span></li>
    <li><span class="function"><a href="function.mktime.php" class="function" rel="rdfs-seeAlso">mktime()</a> - 日付を Unix のタイムスタンプとして取得する</span></li>
    <li><span class="methodname"><a href="intldateformatter.format.php" class="methodname" rel="rdfs-seeAlso">IntlDateFormatter::format()</a> - 日付/時刻 の値を文字列としてフォーマットする</span></li>
    <li><span class="function"><a href="function.time.php" class="function" rel="rdfs-seeAlso">time()</a> - 現在の Unix タイムスタンプを返す</span></li>
    <li><a href="class.datetimeinterface.php#datetimeinterface.constants.types" class="link">定義済みの定数</a></li>
   </ul>
  </p>
 </div>

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