5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Swift Dateをいつでも使える様に

Posted at

今回の内容

  • よく使うDate()について、メモ感覚ですが書いておきます。

コード

.dateStyle = .full && formatter.timeStyle = .full

        let formatter = DateFormatter()
        formatter.dateStyle = .full
        formatter.timeStyle = .full
        formatter.locale = Locale(identifier: "ja_JP")
        let date = Date()
        print(formatter.string(from: date))
Print結果
        2021年10月29日 金曜日 22時32分46秒 日本標準時

.dateStyle = .long && formatter.timeStyle = .long

        let formatter = DateFormatter()
        formatter.dateStyle = .long
        formatter.timeStyle = .long
        formatter.locale = Locale(identifier: "ja_JP")
        let date = Date()
        print(formatter.string(from: date))
Print結果
        2021年10月29日 22:33:55 JST

.dateStyle = .medium && formatter.timeStyle = .medium

        let formatter = DateFormatter()
        formatter.dateStyle = .medium
        formatter.timeStyle = .medium
        formatter.locale = Locale(identifier: "ja_JP")
        let date = Date()
        print(formatter.string(from: date))
Print結果
        2021/10/29 22:34:47

.dateStyle = .short && formatter.timeStyle = .short

        let formatter = DateFormatter()
        formatter.dateStyle = .short
        formatter.timeStyle = .short
        formatter.locale = Locale(identifier: "ja_JP")
        let date = Date()
        print(formatter.string(from: date))
Print結果
        2021/10/29 22:35

終わり

ご指摘、ご質問などありましたら、コメントまでお願い致します。

5
5
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?