PHP 快速導覽 - 核心延伸函數 日期、時間相關 date_timestamp_set()

內建函數 (function) date_timestamp_set() 用來設定日期物件 (object) 的 UNIX 總秒數

函數說明
DateTime date_timestamp_set(DateTime $object, int $unixtimestamp)$object 為日期物件, $unixtimestamp 為要設定的秒數。


date_timestamp_set() 與 DateTime::setTimestamp() 有相同的功能,舉例如下
<?php
$date = date_create('now', new DateTimeZone('Asia/Taipei'));
date_timestamp_set($date, 0);
echo date_format($date, 'U = Y-m-d H:i:s') . "\n";

$date = new DateTime('now', new DateTimeZone('Asia/Taipei'));
$date->setTimestamp(378854602);
echo $date->format('U = Y-m-d H:i:s') . "\n";

/* 《程式語言教學誌》的範例程式
    http://pydoing.blogspot.com/
    檔名:datetime27.php
    功能:示範 PHP 程式 
    作者:張凱慶
    時間:西元 2013 年 2 月 */
?>


執行結果如下



中英文術語對照
函數function
物件object


您可以繼續參考
日期、時間相關的類別與函數


相關目錄
回 PHP 快速導覽
回 PHP 教材
回首頁


參考資料
http://www.php.net/manual/en/function.date-timestamp-set.php
http://www.php.net/manual/en/datetime.settimestamp.php

沒有留言: