我有一个timePicker,如果用户更改了textFiled上的时间字符串设置,我已经声明了一个侦听器。
buildscript {
...
repositories {
mavenCentral()
maven { url "https://maven.fabric.io/public" }
google()
jcenter()
}
...
}
allprojects {
repositories {
mavenCentral()
maven { url "https://maven.fabric.io/public" }
google()
jcenter()
}
}
这是监听器功能:
func timeFromAction(){
DispatchQueue.main.async {
self.timePickerFrom.datePickerMode = UIDatePickerMode.time
//self.timePickerFrom.minimumDate = self.minDate
print(self.minDate)
self.timePickerFrom.date = self.minDate // current date I have achieve from millisecond to date
self.timePickerFrom.locale = Locale(identifier: "fa_IR")
self.timePickerFrom.calendar = Calendar(identifier: Calendar.Identifier.persian)
self.timePickerFrom.timeZone = TimeZone(abbreviation: "IRST")
self.timePickerFrom.frame=CGRect(x: 0, y: 0, width: 288, height: 83)
self.timeOfLoading.addSubview(self.timePickerFrom)
self.timePickerFrom.addTarget(self, action: #selector(self.dateChangedFrom(_:)), for: .valueChanged)
}
}
所以问题是我无论何时更改时间,无论是小时还是分钟,时间都会向前移动1小时。
在侦听器功能中,我从timePicker获取日期,虽然我在其上设置了正确的日期,但在打印时它是错误的
更新:
func dateChangedFrom(_ sender: Any) {
let date = self.timePickerFrom.date
print(date)
let components = Calendar.current.dateComponents([.hour, .minute], from: date)
let hour = components.hour!
let minute = components.minute!
self.timeOfloadingLable.text = "\(hour):\(minute)"
}
这是我使用的功能:
self.minDate=self.crrnt.getComperehensiveDate()
时间是11:59,如下所示向我显示11:33
观看此视频:link
答案 0 :(得分:0)
我刚刚检查了您的代码,它工作正常,请确保您的longDate
是正确的。
您传递了错误的纪元时间。在此处检查您的纪元时间:https://www.epochconverter.com/