Reputation: 1965
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. 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
Upvotes: 0
Views: 687
Reputation: 1169
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. If you want to print date in your timezone, use a NSDateFormatter again. To see date of other time zone, set NSDateFormatter timeZone.
Hope this explains.
Upvotes: 2