Swift

未分類

ViewController.swift

import UIKit
class ViewController: UIViewController {
@IBOutlet var label: UILabel
@IBAction func buttonTap(sender: AnyObject) {
let now = NSDate() // 現在日時の取得
let dateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale(localeIdentifier: “ja_JP”) // ロケールの設定
dateFormatter.dateFormat = “yyyy/MM/dd HH:mm:ss” // 日付フォーマットの設定
label.text = dateFormatter.stringFromDate(now)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}