gpt4 book ai didi

ios - UIDatePicker 快速显示错误的时间

转载 作者:行者123 更新时间:2023-11-30 13:32:25 27 4
gpt4 key购买 nike

func show(title: String, doneButtonTitle: String = "Done", cancelButtonTitle: String = "Cancel", defaultDate: NSDate = NSDate(), datePickerMode: UIDatePickerMode = .DateAndTime, callback: DatePickerCallback) {
self.titleLabel.text = title
self.doneButton.setTitle(doneButtonTitle, forState: .Normal)
self.cancelButton.setTitle(cancelButtonTitle, forState: .Normal)
self.datePickerMode = datePickerMode
self.callback = callback
self.defaultDate = defaultDate
self.datePicker.datePickerMode = self.datePickerMode ?? .Date
self.datePicker.date = self.defaultDate ?? NSDate()
self.datePicker.locale = NSLocale.currentLocale()
/* */
UIApplication.sharedApplication().windows.first!.addSubview(self)
UIApplication.sharedApplication().windows.first!.endEditing(true)

NSNotificationCenter.defaultCenter().addObserver(self, selector: "deviceOrientationDidChange:", name: UIDeviceOrientationDidChangeNotification, object: nil)

/* Anim */
UIView.animateWithDuration(
0.2,
delay: 0,
options: UIViewAnimationOptions.CurveEaseInOut,
animations: { () -> Void in
self.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.4)
self.dialogView!.layer.opacity = 1
self.dialogView!.layer.transform = CATransform3DMakeScale(1, 1, 1)
},
completion: nil
)
}

嗨,当我调用 self.datePicker.date 时,返回 3 小时前。我如何解决这个问题我添加了 self.datePicker.locale = NSLocale.currentLocale() 但问题没有解决。如果需要,我可以添加更多信息。

最佳答案

日期选择器使用本地时间,但存储 UTC 时间。这意味着你的本地时间偏移是-5小时。您可以按照以下步骤从中提取正确的日期和时间:

extension NSDate {
var localTime: String {
return descriptionWithLocale(NSLocale.currentLocale())!
}
}

println(chosenDate.localTime)

支持Leo `

关于ios - UIDatePicker 快速显示错误的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36427700/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com