LoginSignup
0
1

More than 5 years have passed since last update.

iOSの時計が12時間表記のときにアプリ側で24時間表記にする

Posted at

サンプルソース

DateFormatter+format.swift
extension DateFormatter {

    class func allFormat(date: Date) -> String {
        let format = DateFormatter()
        format.dateFormat = "yyyy/MM/dd HH:mm"
        format.calendar = Calendar(identifier: Calendar.Identifier.gregorian)
        format.locale = NSLocale.system
        format.timeZone = NSTimeZone.system
        return format.string(from: date)
    }
}

上記のようなextensionを作ってやればいいかなと

呼び出す場合は以下

ViewController.swift
class ViewController: UIViewController {
    ・・・
    func hoge() {
        print(DateFormatter.allFormat(date: Date()))
    }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1