未分類

DateFormatterの使い方

投稿日:2020年8月2日 更新日:

Date型の日付を文字列にして表示する。

let date = Date()
import Foundation

//フォーマットを指定
let formatter = DateFormatter()
formatter.dateFormat = "yyyy/MM/dd"
let day1 = formatter.string(from: date)

//フォーマットは自由に変えられる
formatter.dateFormat = "yyyy/M"
let day2 = formatter.string(from: date)

//規定のdateStyleを使う
formatter.dateStyle = .medium
let day3 = formatter.string(from: date)

print(date)
print(day1)
print(day2)
print(day3)

参考:DateFormatterの使い方まとめ

-未分類

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

キーボードを閉じるメソッド

//適当な場所をタッチでキーボードを閉じる override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent? …

no image

GoogleService-Info.plistでエラーが出た時の対処法

エラ〜:reason: ‘[FIRApp configure]; (FirebaseApp.configure() in Swift) could not find a valid Goo …

no image

NavigationControllerを用いた画面遷移

ViewControllerを選択→Editor→Embed In→NavigationController NavigationControllerとNavigationBarが出てくる。 View …

プレミアプロ講座基礎編3_仕上げ・書き出し

音量 オーディオメーターが−6くらいが丁度良い。それ以上なら調整する。 BGMをクリックしてエフェクトコントロール→ボリューム→レベル キーを一旦外してから数値を下げて、再びキーを売打つとBGM全体が …

no image

画面遷移の2つの方法

1.簡単な方法 Buttonを次の場面にControl押しながらドラックアンドドロップする。 基本、showかPresentModallyを選ぶ。 2.コードで繋ぐ方法 条件つきで画面遷移したい時に使 …