ホーム

Swift3のDate で (時間・分・秒)を取得する方法

実装

ViewController.swift
  override func viewDidLoad() {
        super.viewDidLoad()

        let date = Date()
        let calendar = Calendar.current

        let hour = calendar.component(.hour, from: date)
        let minutes = calendar.component(.minute, from: date)
        let seconds = calendar.component(.second, from: date)
        print("hours = \(hour):\(minutes):\(seconds)")

    }

参照

How to get time (hour, minute, second) in Swift 3 using NSDate?

Pocket
LinkedIn にシェア

-ホーム

Copyright© off.tokyo , 2021 All Rights Reserved Powered by AFFINGER5.