//
// ViewController.swift
// DatePicker
//
// Created by stayfoolish on 2018. 8. 22..
// Copyright © 2018년 stayfoolish. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
let timeSelector: Selector = #selector(ViewController.updateTime)
let interval = 1.0
var count = 0
@IBOutlet var lblCurrentTime: UILabel!
@IBOutlet var lblPickerTime: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Timer.scheduledTimer(timeInterval: interval, target: self, selector: timeSelector,
userInfo: nil, repeats: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func changeDatePicker(_ sender: UIDatePicker) {
let datePickerView = sender
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss EEE"
lblPickerTime.text = "선택시간: " + formatter.string(from: datePickerView.date)
}
@objc func updateTime() {
// lblCurrentTime.text = String(count)
// count = count + 1
let date = NSDate()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss EEE"
lblCurrentTime.text = "현재시간: " + formatter.string(from: date as Date)
}
}
'Swift > 기초&문법' 카테고리의 다른 글
스위프트 swift music player 음악재생 앱 (0) | 2018.08.27 |
---|---|
스위프트 swift 피커뷰 원하는 이미지 선택 (0) | 2018.08.24 |
스위프트 swift 원하는 이미지 화면 출력 앱 (0) | 2018.08.22 |
스위프트 swift 열거형 enum (0) | 2018.08.21 |
스위프트 swift 클래스 class (0) | 2018.08.21 |