Converting an ISO 8601 timestamp into an NSDate: How does one deal with the UTC time offset?

No need to remove the :’s. To handle the “00:00” style timezone, you just need “ZZZZ”: Swift let dateString = “2014-07-06T07:59:00Z” let dateFormatter = NSDateFormatter() dateFormatter.locale = NSLocale(localeIdentifier: “en_US_POSIX”) dateFormatter.dateFormat = “yyyy-MM-dd’T’HH:mm:ssZZZZ” dateFormatter.dateFromString(dateString) Objective-C NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; dateFormat.locale = [[NSLocale alloc] initWithLocaleIdentifier:@”en_US_POSIX”]; NSString *input = @”2013-05-08T19:03:53+00:00″; [dateFormat setDateFormat:@”yyyy-MM-dd’T’HH:mm:ssZZZZ”]; //iso 8601 format NSDate … Read more

NSDate() vs NSDate.date() in Swift

[NSDate date] is a factory method for constructing an NSDate object. If you read the guide “Using Swift with Cocoa and Objective-C”, there is a section on interacting with Objective-C apis: For consistency and simplicity, Objective-C factory methods get mapped as convenience initializers in Swift. This mapping allows them to be used with the same … Read more

How to convert NSDate in to relative format as “Today”,”Yesterday”,”a week ago”,”a month ago”,”a year ago”?

For simplicity I’m assuming that the dates you are formatting are all in the past (no “tomorrow” or “next week”). It’s not that it can’t be done but it would be more cases to deal with and more strings to return. You can use components:fromDate:toDate:options: with whatever combination of date components you are looking for … Read more

How do I convert a date/time string into a different date string?

This may be useful for who want to use dateformatter.dateformat; if you want 12.09.18 you use dateformatter.dateformat = “dd.MM.yy” Wednesday, Sep 12, 2018 –> EEEE, MMM d, yyyy 09/12/2018 –> MM/dd/yyyy 09-12-2018 14:11 –> MM-dd-yyyy HH:mm Sep 12, 2:11 PM –> MMM d, h:mm a September 2018 –> MMMM yyyy Sep 12, 2018 –> MMM … Read more

Why does NSDateFormatter return nil date for these 4 time zones?

I have a suspicion. Only a suspicion, but a pretty strong one. That value represents October 19th 2064. The Brazilian time zones observe daylight saving time starting at local midnight – that’s when their clocks go forward, so midnight itself doesn’t exist. October 19th is one of those transitions. Here’s some sample code using Noda … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)