このエラーを生成する次のコードがあります: Fatal error: Call to a member function setTimeZone() on a non-object in C:\wamp\www\grid2.php 行 58
以下のように日付文字列を取得し、時間オフセットを適用してから、関数呼び出しで設定された形式で出力するようにこの関数を設定しようとしています...しかし、うまくいきません。
<?php
if (!session_id()) session_start();
$_SESSION["timeoffset"] = "Europe/Amsterdam";
function formatDate($date, $format){
// use the the appropriate timezone for your stamp
$timestamp = DateTime::createFromFormat($format, $date, new DateTimeZone('UTC'));
// set it to whatever you want to convert it
$timestamp->setTimeZone(new DateTimeZone($_SESSION["timeoffset"]));
echo $timestamp->format($format);
}
formatDate('2012-10-14T21:15', 'Y-m-d\TH:i');
?>
また、特定の分数を追加した文字列を返す方法を理解しようとしています。
したがって、文字列 "2012-10-14T21:15" には 5 分が追加されます = "2012-10-14T21:20"
どんな助けでも大歓迎です!
ジェフ