1

I'm trying to display the current year using Zend Framework 2, the documentation that I've found does not cover how to output custom date formats.

Documentation can be found here: https://packages.zendframework.com/docs/latest/manual/en/modules/zend.i18n.view.helper.date.format.html?highlight=dateformat

If anyone could provide me with the syntax Zend Framework 2 syntax to output custom date/time formats it would be greatly appreciated. Thank you!

4

2 に答える 2

3

ここでこの質問を見てください。

ここに答えをコピーして貼り付けます: PHP 5.3 DateTime API を優先して Zend_Date が削除されましたhttp://es.php.net/manual/en/book.datetime.php

また、ZF2 の DateFormat Helper のソース コードを見ると、それは不可能のようです。基本的に、十分に十分なphpクラスでそれを行うだけです。

Zend Framework 1 または 2 がすべてをラップしているわけではありません。php の一部がそのままで完全な場合は、置き換えられません。

編集:これは質問者にとってうまくいきました:

$datetime = new DateTime(null, new DateTimeZone('America/Chicago')); 
echo $datetime->format('Y');
于 2013-01-11T03:02:25.773 に答える
2

Zend Framework 2 は、特定の日付オブジェクトを提供しなくなりました。代わりに、ネイティブの php DateTimeで動作します。オブジェクトを使用DateTimeすると、それらをヘルパーで使用して出力を変換できます。

また、あなたが言及したビューヘルパーは、i18n専用です。タイムスタンプの形式は国ごとに異なるため、ヘルパーはそのためのものです。ただし、2013 年は米国、英国、中国では 2013 年です。そのために i18n を使用する必要はありません。

したがって、現在の年は単純にDateTime直接使用され、date() フォーマット パラメータでフォーマットされます。

$date = new DateTime;

$date->format('o'); // ISO-8601 year, four digits
$date->format('Y'); // Four digits
$date->format('y'); // Two digits

おそらく、Yまたはのいずれかを使用する必要がありyます。

于 2013-01-11T09:46:08.927 に答える