2011-07-15 33 views
0

使用Zend語言環境是否有時間轉換時間,比如說17:00到下午5:00?使用Zend語言環境進行時間轉換

我試過文檔中的方法(它有一個錯字),但它不起作用。它提供錯誤 '無法分析日期'13:44:42' 使用 '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"; 
} 

我然後嘗試了2步驟的方法,在獲取時刻格式首先使用當前語言環境,然後在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') 

是否有東西,將時間轉化爲實際的語言環境,我試圖將其解析到?

回答

0

您需要使用Zend_Date並使用語言環境以所需格式獲取日期。

$date = new Zend_Date(); // Default ISO format type & en_US 
// Set the time and pass the format I am using to set the time 
$date->setTime('17:00:00', 'HH:mm:ss'); 
echo $date; // Jul 15, 2011 5:00:00 PM 

編輯

更多關於你如何使用Zend_LocaleZend_Date

$locale = new Zend_Locale('de_AT'); 
echo $date->toString(Zend_Locale_Format::getTimeFormat($locale)) ; // 17:00:00 
$locale = new Zend_Locale('en_US'); 
echo $date->toString(Zend_Locale_Format::getTimeFormat($locale)) ; // 5:00:00 PM 
+0

謝謝你的幫助布雷迪,我只是想用Zend_Locale_Format做這一切地,Zend_Date幫助了很多。我結束了使用這樣的東西 '$ locale = new Zend_Locale('en_US'); $ date = new Zend_Date($ locale); $ date-> setTime($ hour-> open); $ open = $ date-> get(Zend_Date :: TIME_SHORT);' – JasonM

相關問題