<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.datetimeimmutable.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'datetimeimmutable.modify.php',
    1 => 'DateTimeImmutable::modify',
    2 => 'タイムスタンプを変更した新しいオブジェクトを作る',
  ),
  'up' => 
  array (
    0 => 'class.datetimeimmutable.php',
    1 => 'DateTimeImmutable',
  ),
  'prev' => 
  array (
    0 => 'datetimeimmutable.getlasterrors.php',
    1 => 'DateTimeImmutable::getLastErrors',
  ),
  'next' => 
  array (
    0 => 'datetimeimmutable.set-state.php',
    1 => 'DateTimeImmutable::__set_state',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/datetime/datetimeimmutable/modify.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="datetimeimmutable.modify" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTimeImmutable::modify</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DateTimeImmutable::modify</span> &mdash; <span class="dc-title">タイムスタンプを変更した新しいオブジェクトを作る</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetimeimmutable.modify-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="attribute"><a href="class.nodiscard.php">#[\NoDiscard]</a> </span><br>
   <span class="modifier">public</span> <span class="methodname"><strong>DateTimeImmutable::modify</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$modifier</code></span>): <span class="type"><a href="class.datetimeimmutable.php" class="type DateTimeImmutable">DateTimeImmutable</a></span></div>

  <p class="para rdfs-comment">
   タイムスタンプを変更した新しい <span class="type"><a href="class.datetimeimmutable.php" class="type DateTimeImmutable">DateTimeImmutable</a></span> オブジェクトを作ります。
   元のオブジェクトは変更されません。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetimeimmutable.modify-parameters">
  <h3 class="title">パラメータ</h3>
  <dl>
   
    <dt><code class="parameter">modifier</code></dt>
    <dd>
     <p class="para">日付/時刻 文字列。有効な書式については <a href="datetime.formats.php" class="link">日付と時刻の書式</a> で説明しています。</p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-datetimeimmutable.modify-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   成功時に <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span> を返します。
   手続き型 の場合は、失敗したときに <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-datetimeimmutable.modify-errors">
  <h3 class="title">エラー / 例外</h3>
  <p class="para">
   不正な日付/時刻の文字列が渡された場合、
   <span class="exceptionname"><a href="class.datemalformedstringexception.php" class="exceptionname">DateMalformedStringException</a></span> がスローされます。
   PHP 8.3.0 より前のバージョンでは、警告が発生していました。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-datetimeimmutable.modify-changelog">
  <h3 class="title">変更履歴</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>バージョン</th>
      <th>説明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       無効な文字列が渡された場合、
       <span class="methodname"><strong>DateTimeImmutable::modify()</strong></span>
       は <span class="exceptionname"><a href="class.datemalformedstringexception.php" class="exceptionname">DateMalformedStringException</a></span>
       をスローするようになりました。
       これより前のバージョンでは、
       警告が発生して <code class="literal">false</code> を返していました。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 <div class="refsect1 examples" id="refsect1-datetimeimmutable.modify-examples">
  <h3 class="title">例</h3>
  <div class="example" id="example-1">
   <p><strong>例1 <span class="function"><strong>DateTimeImmutable::modify()</strong></span> の例</strong></p>
   <div class="example-contents"><p>オブジェクト指向型</p></div>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$date </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">(</span><span style="color: #DD0000">'2006-12-12'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$newDate </span><span style="color: #007700">= </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'+1 day'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$newDate</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</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">2006-12-13</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-2">
   <p><strong>例2 月の加減算には注意</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$date </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">(</span><span style="color: #DD0000">'2000-12-31'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$newDate1 </span><span style="color: #007700">= </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'+1 month'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$newDate1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$newDate2 </span><span style="color: #007700">= </span><span style="color: #0000BB">$newDate1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'+1 month'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$newDate2</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</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">2001-01-31
2001-03-03</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-datetimeimmutable.modify-seealso">
  <h3 class="title">参考</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="datetimeimmutable.add.php" class="function" rel="rdfs-seeAlso">DateTimeImmutable::add()</a> - 年月日時分秒の値を加え、新しいオブジェクトを返す</span></li>
   <li><span class="function"><a href="datetimeimmutable.sub.php" class="function" rel="rdfs-seeAlso">DateTimeImmutable::sub()</a> - 年月日時分秒の値を引く</span></li>
   <li><span class="function"><a href="datetimeimmutable.setdate.php" class="function" rel="rdfs-seeAlso">DateTimeImmutable::setDate()</a> - 日付を設定する</span></li>
   <li><span class="function"><a href="datetimeimmutable.setisodate.php" class="function" rel="rdfs-seeAlso">DateTimeImmutable::setISODate()</a> - ISO 日付を設定する</span></li>
   <li><span class="function"><a href="datetimeimmutable.settime.php" class="function" rel="rdfs-seeAlso">DateTimeImmutable::setTime()</a> - 時刻を設定する</span></li>
   <li><span class="function"><a href="datetimeimmutable.settimestamp.php" class="function" rel="rdfs-seeAlso">DateTimeImmutable::setTimestamp()</a> - Unix タイムスタンプを用いて日付と時刻を設定する</span></li>
  </ul>
 </div>


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