java如何获取当前系统时间ns级别_获取时间戳格式的当前NSDate

迅速:

我有一个UILabel,它在Camera Preview上显示TimeStamp .

var timeStampTimer : NSTimer?

var dateEnabled: Bool?

var timeEnabled: Bool?

@IBOutlet weak var timeStampLabel: UILabel!

override func viewDidLoad() {

super.viewDidLoad()

//Setting Initial Values to be false.

dateEnabled = false

timeEnabled = false

}

override func viewWillAppear(animated: Bool) {

//Current Date and Time on Preview View

timeStampLabel.text = timeStamp

self.timeStampTimer = NSTimer.scheduledTimerWithTimeInterval(1.0,target: self, selector: Selector("updateCurrentDateAndTimeOnTimeStamperLabel"),userInfo: nil,repeats: true)

}

func updateCurrentDateAndTimeOnTimeStamperLabel()

{

//Every Second, it updates time.

switch (dateEnabled, timeEnabled) {

case (true?, true?):

timeStampLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .LongStyle, timeStyle: .MediumStyle)

break;

case (true?, false?):

timeStampLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .LongStyle, timeStyle: .NoStyle)

break;

case (false?, true?):

timeStampLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .NoStyle, timeStyle: .MediumStyle)

break;

case (false?, false?):

timeStampLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .NoStyle, timeStyle: .NoStyle)

break;

default:

break;

}

}

我正在设置一个设置按钮来触发alertView .

@IBAction func settingsButton(sender : AnyObject) {

let cameraSettingsAlert = UIAlertController(title: NSLocalizedString("Please choose a course", comment: ""), message: NSLocalizedString("", comment: ""), preferredStyle: .ActionSheet)

let timeStampOnAction = UIAlertAction(title: NSLocalizedString("Time Stamp on Photo", comment: ""), style: .Default) { action in

self.dateEnabled = true

self.timeEnabled = true

}

let timeStampOffAction = UIAlertAction(title: NSLocalizedString("TimeStamp Off", comment: ""), style: .Default) { action in

self.dateEnabled = false

self.timeEnabled = false

}

let dateOnlyAction = UIAlertAction(title: NSLocalizedString("Date Only", comment: ""), style: .Default) { action in

self.dateEnabled = true

self.timeEnabled = false

}

let timeOnlyAction = UIAlertAction(title: NSLocalizedString("Time Only", comment: ""), style: .Default) { action in

self.dateEnabled = false

self.timeEnabled = true

}

let cancel = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .Cancel) { action in

}

cameraSettingsAlert.addAction(cancel)

cameraSettingsAlert.addAction(timeStampOnAction)

cameraSettingsAlert.addAction(timeStampOffAction)

cameraSettingsAlert.addAction(dateOnlyAction)

cameraSettingsAlert.addAction(timeOnlyAction)

self.presentViewController(cameraSettingsAlert, animated: true, completion: nil)

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值