2016-04-14 12 views
0

でNSDateから数分の文字列()は常に、時間で現在の時刻を返すいただきました!間違ってこのコードの上の任意のアイデアを11時04分を出力しますか?あなたが代わりに分の数ヶ月を使用している正しい時間を取得することができません:分:スウィフト

import UIKit 

extension NSDate { 

    func currentTimeInHoursAndMinutes() -> String { 

     let dateFormatter = NSDateFormatter() 
     dateFormatter.locale = NSLocale.currentLocale() 
     dateFormatter.timeZone = NSTimeZone.localTimeZone() 
     dateFormatter.dateFormat = "HH:MM" 
     let timeStr = dateFormatter.stringFromDate(self) 
     print("timeStr:\(timeStr) for nsdate:\(self)") 
     return timeStr 
    } 
} 

let time = NSDate().currentTimeInHoursAndMinutes() 
+0

は全体の印字行を表示し、そしてどのようにあなたはこれを上の呼び出しの日付を作成しています。 – Wain

答えて

0

、この時間の残りのために、あなたが月に使用し続ける場合は、同じ時間になるように表示されます。

dateFormatter.dateFormat = "HH:mm" 

Unicode Date Format Patterns

関連する問題