Let me give an example of what am trying to achieve: Say i am in Hong Kong [HKT] and on my app all i need to know if the current time in America/Sitka is after evening 5:30PM or not. [i have to execute a piece of code after certain time and will continue to do that till next morning sometime.]
Now in my app i have the information for home time zone and the remote time zone . (have NSTimeZone object for the same)
I can print the time for both if i want, using this code.
var nTZ:NSTimeZone = NSTimeZone(name: "America/Sitka")
var dateFormatter: NSDateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "hh:mm a"
dateFormatter.timeZone = NSTimeZone(abbreviation: nTZ.abbreviation!)
var remoteTime: NSSTring = dateFormatter.stringFromDate(NSDate())
Now the problem is that dateformatter converts date into string format. And how do i figure out if currently the time in the remote place is after say evening 5:30PM. Basically how to compare the time?
One thing which i also tried was reversing the time to NSDate. ie. take the String date and convert back to NSDate. Idea was if i can convert it to a Date format i will try some kind of comparison (which i have yet to figure out.) //Below code is continuation of previous code
var dateFormatter2: NSDateFormatter = NSDateFormatter()
dateFormatter2.dateFormat = "HH:mm a"
var tempDateX:NSDate = dateFormatter2.dateFromString(remoteTime)!
println(tempDateX)
This do show some value but that doesn't matches the original date. Looks like it prints the time minus by current GMT offset. Not sure why.
Please help me with this problem. Appreciate your help.