> On Dec 8, 2015, at 2:04 PM, Eric E. Dolecki <edole...@gmail.com> wrote:
> 
> I tried an extension I found. It's off by 5 hours...
> 
> extension NSDate
> {
>    convenience
>    init(dateString:String) {
>        let dateStringFormatter = NSDateFormatter()
>        dateStringFormatter.calendar = NSCalendar(calendarIdentifier:
> NSCalendarIdentifierGregorian)
>        dateStringFormatter.dateFormat = "yyyy-MM-dd HH:mm"
>        dateStringFormatter.locale = NSLocale(localeIdentifier:
> "en_US_POSIX")
>        dateStringFormatter.timeZone = NSTimeZone.localTimeZone()
>        let d = dateStringFormatter.dateFromString(dateString)!
>        self.init(timeInterval:0, sinceDate:d)
>    }
> }
> 
> ...
> 
> let calendar = NSCalendar.currentCalendar()
>        calendar.timeZone = NSTimeZone.localTimeZone()
>        calendar.locale = NSLocale(localeIdentifier: "en_US_POSIX")
>        let startDate = NSDate(dateString:"2015-12-08 7:30")
>        let date = calendar.dateByAddingUnit(.Minute, value: 5, toDate:
> startDate, options: [])
> *        print (date!) //This is way off. How to fix this?*

What is the value of print(startDate) ? 

What do you get if you display `date` and `startDate` using an NSDateFormatter 
instead of print() ?

I bet `date` and `startDate` are in fact five minutes apart, but either your 
date construction or your date display are not using the time zone you expect.


-- 
Greg Parker     gpar...@apple.com     Runtime Wrangler



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to