LoginSignup
17
17

More than 5 years have passed since last update.

【Swift3】現在時刻の取得とDataFormatterでの文字列化

Posted at

また備忘メモで恐縮です・・
この辺りがググっても古いコードが出てくる状況です。xcodeもここまで修正はしてくれません。

こんなかんじで

    func getNowClockString() -> String {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd' 'HH:mm:ss"
        let now = Date()
        return formatter.string(from: now)
    }

とやると

2016-09-28 09:02:37

とか出ますので、これで時計系のアプリとかログとかに使えるかと思います。

17
17
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
17
17