使用 Zend 语言环境进行时间转换
有没有办法使用 Zend Locale 转换时间(例如 17:00 到 5:00pm)?
我已经尝试了文档中的方法(有错字),但它不起作用。它给出错误“无法使用 'dd.MM.yyyy' (M <> y) 解析日期 '13:44:42'”
$locale = new Zend_Locale('de_AT');
if (Zend_Locale_Format::getTime('13:44:42',
array('date_format' =>
Zend_Locale_Format::STANDARD,
'locale' => $locale))) {
print "time";
} else {
print "not a time";
}
然后我尝试了两步方法,首先获取当前区域设置的时间格式,然后在 getTime 函数中使用它。
$locale = new Zend_Locale('en_US');
$tf = Zend_Locale_Format::getTimeFormat($locale);
$test = Zend_Locale_Format::getTime('17:00', array('date_format' => $tf, 'locale' => $locale));
这会返回一个结果,但只是返回我所拥有的内容
array('date_format'=>'h:mm:ss a', 'locale'=>'en_US', 'hour'=>'17', 'minute'=>'00')
是否有什么东西可以将时间转换为我试图解析它的实际语言环境?
Is there a way of converting a time, say 17:00 to 5:00pm using Zend Locale?
I've tried the method in the docs as it is (which has a typo), but it doesn't work. It gives the error 'Unable to parse date '13:44:42' using 'dd.MM.yyyy' (M <> y)'
$locale = new Zend_Locale('de_AT');
if (Zend_Locale_Format::getTime('13:44:42',
array('date_format' =>
Zend_Locale_Format::STANDARD,
'locale' => $locale))) {
print "time";
} else {
print "not a time";
}
I then tried a 2 step method, getting the time format of the current locale first, and then using that in the getTime function.
$locale = new Zend_Locale('en_US');
$tf = Zend_Locale_Format::getTimeFormat($locale);
$test = Zend_Locale_Format::getTime('17:00', array('date_format' => $tf, 'locale' => $locale));
This returns a result but just gives me back what I had
array('date_format'=>'h:mm:ss a', 'locale'=>'en_US', 'hour'=>'17', 'minute'=>'00')
Is there something that will convert the time to the actual locale I'm trying to parse it to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
Zend_Date
与语言环境结合使用,以获取所需格式的日期。编辑
有关如何将
Zend_Locale
与Zend_Date
结合使用的更多信息You need to be using
Zend_Date
with the locale to get the date in the format you want.EDIT
More on how you can use
Zend_Locale
withZend_Date