[英]NSDateformatter does not provide correct date swift
When I am using NSDateformatter to get date from string it returns wrong value.I dont know what must be reason.Please help me to resolve. 当我使用NSDateformatter从字符串获取日期时,它返回错误的值。我不知道一定是原因。请帮助我解决。 Thanks in advance.
提前致谢。
Input String:-
newDate "06:11"
end time "07:00"
start time "05:00"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "HH:mm"
let date:NSDate = dateFormatter.dateFromString(dateString)!
println(date)
Output Date:-
current date 2000-01-01 00:41:00 +0000
end date 2000-01-01 01:30:00 +0000
start date 1999-12-31 23:30:00 +0000
By doing 通过做
println(date)
You are printing the description of the date, which is equal to - 您正在打印日期的说明,该说明等于-
println(date.description())
And it always prints the time in UTC (GMT) So if you are in UTC+5:30, it will display time that is before 5:30 hours than your entered time. 而且它始终以UTC(GMT)格式显示时间,因此,如果您使用的是UTC + 5:30,它将显示比您输入的时间早5:30小时的时间。 If you want to print date in your timezone, use a NSDateFormatter again.
如果要在时区中打印日期,请再次使用NSDateFormatter。 To see date of other time zone, set NSDateFormatter timeZone.
要查看其他时区的日期,请设置NSDateFormatter timeZone。
Hope this explains. 希望这能解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.