FAQ Database Discussion Community


NSDate value is always returned in my time zone

objective-c,nsdate,nsdateformatter
TL/DR: I need an NSDate representing 1970-01-01 00:00:00 +0000 specifically. Using [NSDate dateWithTimeIntervalSince1970:0] returns the date adjusted for my time zone. I can't figure out how to fix this. I am attempting to write an Objective-C iOS test that revolves around NSDates. The trouble is, any NSDate object I try...

Not getting correct date from NSDate

ios,nsdate,nsdateformatter
I am new in iOS programming and i want to get difference between two NSDate objects but i am not able to calculate correct difference as i am not getting correct date from [NSDate Date]. Have a look at attached screenshot. I am not getting what i am doing wrong?...

NSDateFormatter- stringFromDate not returning AM/PM

ios,datetime,nsdate,nsdateformatter,date-format
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"hh:mm:ss a"]; NSLog(@"Today's Time: %@", [formatter stringFromDate:[NSDate date]]); The above code just gives the following output Today's Time: 15:46:43 I want the output to be Today's Time: 3:46 PM. I surfed a lot and i did not find a way to show...

NSDateFormatter detect 24-hour clock in OS X and iOS

swift,nsdate,nsdateformatter
I would like to check if the user has selected the 12-hour or 24-hour clock as their preference in OS X and iOS. So I would like to detect if the user has done the following: On the Mac, the System Preference is in Date & Time, Use a 24-hour...

Swift code with multiple NSDateFormatter - optimization

ios,swift,core-data,nsdateformatter
For swift learning purposes, I'm work on personal Core Data project. So far everything is working, but I cannot figure out how to optimize the code. By optimization I mean only visual optimization, the performance is different story and is too early for me. In the class below I'm using...

NSDateFormatter returning wrong minutes

ios,nsdateformatter
I am converting a server timestamp that is a NSString to a NSDate however I am getting the wrong time. Please help. Here is my code. NSLog(@"string %@", string); // Setup Date Formatter NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setTimeZone:[NSTimeZone defaultTimeZone]]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.zzzZ"]; // Get Date From String NSDate *dateOfCall...

NSDateFormatter dateFromString return wrong year

ios,nsdate,nsdateformatter
I have these following snippet. NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat : @"yyyy/MM/dd"]; NSString *timeStr = @"2015/05/16"; NSDate *timeDate = [formatter dateFromString:timeStr]; But when I print timeDate in console,the output is werid.The year becomes 4003. 4003-05-16 16:00:00 +0000 I test it in iPad 8.3(12F69)(not simulator).System time zone is...

DateFormatter for format 'Fri, 19 Jun 2015 20:05:23 GMT'

ios,objective-c,nsdate,nsdateformatter
I am trying to determine the DateFormatter dateFormat element for the following timestamp: Fri, 19 Jun 2015 20:05:23 GMT I have tried the following without success: E', dd MMM yyyy hh:mm:ss zzz EE', dd MMM yyyy hh:mm:ss zzz EEE', dd MMM yyyy hh:mm:ss zzz E', dd MMM yyyy hh:mm:ss zz...

NSDateFormatter adds 10hours?

ios,nsdate,nsdateformatter
I'm trying to get two dates from strings, so code below: NSString *serverDateString = array[0]; NSString *nextEventDateString = array[1]; NSDateFormatter *dateFormatter = [NSDateFormatter new]; [dateFormatter setDateFormat:@"hh:mm dd.MM.yyyy"]; timer.serverTime = [dateFormatter dateFromString:serverDateString]; timer.nextEventTime = [dateFormatter dateFromString:nextEventDateString]; But what i get : (lldb) po serverDateString 12:15 16.03.2015 (lldb) po nextEventDateString 00:00 17.03.2015...

How to get system time format when region is “United Kingdom” in ios?

ios,objective-c,iphone,nsdateformatter,date-formatting
I am using the following code for get system time format in ios. And it work fine when my current region set with "United State" but when I change the region from "United State" to "United Kingdom" it always give 12 hour formate. #pragma mark #pragma mark - get system...

How to convert NSString to NSDate in IOS?

ios,objective-c,nsstring,nsdate,nsdateformatter
I am building an application where I need to convert The NSString to NSDate. I have googled and found a lot links of SOF mentioned below - http://stackoverflow.com/questions/3917250/converting-nsstring-to-nsdate-and- back-again Convert NSString to NSDate Converting can NSString to NSDate format in objective C I had used the answer given there but...

NSDateComponentsFormatter's stringFromDate(_, toDate:) returns nil

swift,nsdate,nsdateformatter,nsdatecomponents,nsdatecomponentsformatter
Question Why is string nil? let formatter = NSDateComponentsFormatter() let referenceDate = NSDate(timeIntervalSinceReferenceDate: 0) let intervalDate = NSDate(timeInterval: 3628810, sinceDate: referenceDate) let string = formatter.stringFromDate(referenceDate, toDate: intervalDate) I'm expecting a string like "6w 10s" to be returned. (6 weeks is 3,628,800 seconds.) Attempted Troubleshooting To troubleshoot, I tried setting allowedUnits:...

How to get weekends vs weekdays in Cocoa?

cocoa,locale,nsdateformatter,nscalendar
What is the correct calendar-agnostic way (in either iOS or OS X) to get standard business days of the week (e.g. weekdays) versus non-working days of the week? This is taking into account that some parts of the world doesn't follow the Monday through Friday working day routine. E.g. the...

NSArray with week days

ios,objective-c,nsdate,nsdateformatter
I have a question, In my app I have an NSMutableArray which contains name with days of the week, sometimes is just Sunday and Saturday, sometimes is just Monday or Tuesday, my question is: I want that when my array will contain just entry like this: Sunday and Saturday to...

NSDateFormatter for day and month name

ios,objective-c,nsdate,nsdateformatter
I am trying to get date in the format Monday, March 09, 2015. But following code is not returning required date format. I think I am using wrong Formatter. Here is the code: NSString *dateString = @"09-03-2015"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd MMMM yyyy"]; NSDate *date =...

NSDateFormatter dateFormat ShortStyle not working

ios,iphone,swift,xcode6,nsdateformatter
I have some problem with the NSDateFormatter now. When I set the dateStyle to be ShortStyle, the code will work if I set the language of the simulator into Simplified Chinese. If I set the date is 2015-04-20, it will show 15/4/20. According to the documentation, this result is correct....

Swift - convert date string from a “datepicker filled date field” to nsdate

swift,nsdate,nsdateformatter,uidatepicker
Ive got a UIDatepicker attached to a text field named dateField. when the user clicks on the field, a UIDatePicker pops up and the user chooses a date of birth. That date is saved as a string to that dateField and shows up formatted according to the users location ie...

NSDateFormatter returns nil sometimes

ios,nsdateformatter
I created a NSDateFormatter but sometimes it creates an NSDate out of a given string sometimes it doesn't on the same device (Simulator). This is my code: NSString *lastModifiedString = [metaData objectForKey:@"Last-Modified"]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEE, dd MMM yyyy hh:mm:ss Z"]; NSDate *onlineModDate = [dateFormatter dateFromString:lastModifiedString];...

ios8 Timezone parsing changed?

ios,nsdateformatter
Has the parsing for timzones changed in iOS8? I try to parse the date "2014-09-03 12:20:38.000 +0200" with this code and get nil: -(NSDateFormatter*) dateAndTimeFormatter{ if(!_dateAndTimeFormatter){ _dateAndTimeFormatter = [[NSDateFormatter alloc]init]; [_dateAndTimeFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS ZZZZZ"]; _dateAndTimeFormatter.dateStyle = NSDateFormatterShortStyle; _dateAndTimeFormatter.timeStyle = NSDateFormatterShortStyle; } return _dateAndTimeFormatter; } alternatively [_dateAndTimeFormatter setDateFormat:@"yyyy-MM-dd...

time change after converting using NSDateFormatter

objective-c,nsdate,nsdateformatter
I'm trying to convert string to date. it works fine but the hours is different from the string. Here is my sample code: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss a"]; [dateFormat setTimeZone:[NSTimeZone defaultTimeZone]]; [dateFormat setLocale:[NSLocale currentLocale]]; NSDate *date = [dateFormat dateFromString:@"2015-03-09 07:40:00 pm"]; NSLog(@"%@", date); And, the...

CHANGE FORMAT TIME IN OBJECTIVE-C

ios,objective-c,nsdate,nsdateformatter
I need to change the format of my time and my date I search in Google how do that and I find how I can change the data format with that code: NSString *hora=@"01:32"; NSDateFormatter *formatHora = [[NSDateFormatter alloc] init]; [formatHora setDateFormat:@"hh:mm"]; NSDate *dateHora = [formatHora dateFromString:hora]; [formatHora setDateFormat:@"HH:mm"]; NSString*...

Check if time of NSDate object has passed

ios,nsdate,nsdateformatter
Im trying to check if the time of an NSDate has passed. Ive used the following but that obviously has the year so therefore it has passed. How would I check just the time of the NSDate object, only Hour and minutes are important: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];...

IOS: Get current date/time with specific (non-localized) format

ios,objective-c,iphone,string-formatting,nsdateformatter
I want to get the current date/time in a very specific format like this: 2013-11-24_18_12_88 However, using the following code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd_hh_mm_ss"]; NSString *dateString = [dateFormatter stringFromDate:[NSDate date]]; I get this date string instead: 2013-11-24_18:12:88 How can I force the dateFormatter to not delete...

SWIFT : Convert String from XLM to NSDate

ios,swift,nsstring,nsdate,nsdateformatter
The following code works on the simulator but doesn't on devices. I tried to replace Z with xx with no luck. Any help appreciated. Thanks. func convertDateStringToNSDate(dateString: String) -> NSDate { var dateFormatter = NSDateFormatter() // Sat, 20 Jun 2015 16:50:20 +0200 dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss xx"...

cannot invoke 'stringFromDate' error in swift

ios,swift,nsdateformatter
I'm trying to do a simple date format in Swift but I'm getting the following error: "Cannot invoke 'stringFromDate' with an argument list of type '(NSDate?!)'" My code is as follows: override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell //...

How to display only the day and month of a date based on the locale?

ios,swift,nsdateformatter
I would like to display only the day and the month of a date, but I want it based on the user's locale. For example I have the following date: 21/05/2015 00:16:00 GMT+10 I want to have May 21 if the locale is en_US or 21 May if the locale...

NSDateformatter: How to decide date formatter string

date,nsdateformatter,date-formatting
Is there any rule to define date formatter? I have date string as given below Mon Feb 10 09:05:13 PST 2014 How to do i write appropriate date format for this date string to convert date? NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"EEE-MMM-DD-hh:mm:ss-Z-YYYY"]; NSDate * dateFormatted = [dateFormatter dateFromString:date];...

Get current NSDate with a format of: dd/MM/yyyy

objective-c,nsdate,nsdateformatter
I'm trying to get the current date with the following format: dd/MM/yyyy. The way I would format it, is like this: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"dd/MM/yyyy"]; And I would get the current date like this: [NSDate date]. How can I mix the 2 together, and get the...

Issues in converting date string (any time zone) to NSDate of French Time Zone

ios,objective-c,nsdate,nsdateformatter,nstimezone
I want to convert a date string (can be in any time zone) to a date in French Time Zone. I am using following code. NSString * dateString = @"27/05/2015 - 19:00" // system time zone is GMT +5 NSDateFormatter* frenchDateFormatter = [[NSDateFormatter alloc] init]; [frenchDateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Europe/Paris"]]; [frenchDateFormatter setDateFormat:@"dd/MM/yyyy...

Format NSDate to this format in NSString:- January 15 2013

ios,objective-c,iphone,nsdate,nsdateformatter
Currently , I am storing the dates in a NSArray, as I have to load the list of dates in custom drop down view, but can't able to do so because of the following issue. Here is the code how I am trying to format the NSDate:- NSCalendar *currentCalendar =...

Convert long month name to int

swift,cocoa-touch,nsdate,nsdateformatter,date-parsing
I understand how to use an NSDateFormatter to convert a month component into a long name string, but how does one convert a month name to an int? I've been using a switch statement to convert, but I'm thinking there must be a simpler way. For example, I'd like to...

Format NSDate with different calendar identifier?

swift,nsdate,nsdateformatter,nsdatecomponents
I'm trying to print a human-friendly date that's of a different calendar identifier. I am able to get the date, but when I format it, it outputs back to Gregorian (or the user's current calendar I think). Here's what I'm trying: var calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierIslamicCivil) var flags = NSCalendarUnit(UInt.max)...

How do I create a new NSDate object that is in the past, e.g. 1 second earlier than another date?

ios,swift,nsdate,nsdateformatter,nsdatecomponents
So this is how I set a future date: var comp = NSDateComponents() comp.setValue(1, forComponent: NSCalendarUnit.CalendarUnitMonth); let date: NSDate = NSDate() var expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(comp, toDate: date, options: NSCalendarOptions(0)) Now what if I have dateA and want to create a new date (dateB) that is 1 second earlier than dateA....

NSDateFormatter not working to covert NSString to NSDate

nsdateformatter
I am using NSDateFormatter to get a date from an NSString I am confused as to why the following is not working: NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; NSDate *myDate = [df dateFromString: timeDateUpdated]; myDate remains nil and yet, as the image shows the timeDateUpdated appears to...

NSDateFormatter dateFromString format string issue

ios,objective-c,nsdateformatter
I encountered a small problem today: I receive a couple of dates (NSString) from a web server. To use those dates correctly they need to be parsed into NSDate objects, for which I'm using the following code: NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; formatter.dateFormat = @"dd.MM.yyy HH:mm:ss"; return [formatter dateFromString:dateString] The...

NSString to NSDate doesn't work

ios,objective-c,nsdateformatter
now it works with this code: NSString *myDate = @"06/18/2015 8:26:17 AM"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/dd/yyyy hh:mm:ss a"]; [dateFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US"]]; NSDate *date = [dateFormatter dateFromString:myDate]; [dateFormatter setDateFormat:@"dd.MM. HH:mm"]; NSString *dateString = [dateFormatter stringFromDate:date]; cell.timeLabel.text = dateString; ...

Swift date formatting with NSDateFormatter

ios,swift,nsdateformatter
i have a json object that contains a date from database: var showDateRaw = v["feedDate"].description println(showDateRaw) showDateRaw variable's type is String and looks like this way after parsing the json object: 2015-05-10T18:39:55+02:00 i would like to convert it to look like this way: 2015.05.10 - 18:39 First of all i...

How to display time 'just now' '1 minute ago' '1 hour ago' respectively

ios,nsdate,nsdateformatter,nsdatecomponents
I working on an worldwide app, the functionality is I need to display the posted time as 'Just now','1 minute ago' '1 hour ago' respectively. I sending the date and time while creating post and send to webservice.And I retrieving the same date time for each post which I need...

How do I format JSON Date String with Swift?

json,swift,nsdateformatter
I make an http get request to a server and get back a json object with a date string like this: { name = "Place1"; temperature = 79; humidity = 68; reported_at = "2013-07-21T19:32:00Z"; } I want to format the reported_at key so I can display a readable date and...

NSDateFormatter swapping between Style and Format

objective-c,cocoa,cocoa-touch,nsdateformatter
Is it safe to use the same NSDateFormatter and swap between Style and Format definitions? For example: NSDateFormatter *df = [NSDateFormatter new]; df.dateStyle = NSDateFormatterMediumStyle; df.timeStyle = NSDateFormatterMediumStyle; NSLog(@"Medium Style / Medium Time: %@", [df stringFromDate:[NSDate date]]); df.dateFormat = @"MMM/d/yy hh:mm:ss"; NSLog(@"Custom Format: %@", [df stringFromDate:[NSDate date]]); df.dateStyle = NSDateFormatterFullStyle;...

Swift: can't get NSDate dateFormatter right

ios,date,swift,nsdate,nsdateformatter
DateFormatter is acting funny to me: let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MM'/'DD'/'YYYY" var dateString = "09/28/1989" var date = dateFormatter.dateFromString(dateString) println(date) Returns: "Optional(1988-12-24 13:00:00 +0000)" Any kind of help will be appreciated....

NSDateFormatter returning null when trying to fetch date from string

ios,objective-c,nsdate,nsdateformatter
I am trying to get date from string. But it's returning null value. Can anyone tell the reason? I think date formatter is incorrect. Below is the code: NSString *dateString = @"2015-02-28 05:50:15"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-dd-MM HH:mm:ss"]; NSDate *dateFromString = [dateFormatter dateFromString:dateString]; NSLog(@"date: %@", dateFromString);...

NSDateFormatter doing wrong

swift,date,nsdateformatter
i'm trying to get my local date and using the NSDateFormatter to write it in the right way, but i'm getting a mix of en_US with pt_BR (portuguese - Brazil). Here the following code: let br_DateFormat = NSDateFormatter.dateFormatFromTemplate("ddMMMMyyyy", options: 0, locale: NSLocale(localeIdentifier: "pt_BR")) let date = NSDate(); var dateFormatter =...

Create NSDate with String time from 1970

ios,objective-c,nsdate,nsdateformatter
I have a string that its value is time. The time is formmated with "time from 1970". How can I convert this string to a nsdate object?

Parsing a date string gives [__NSDate length] unrecognized selector exception [duplicate]

objective-c,cocoa,cocoa-touch,nsdate,nsdateformatter
This question already has an answer here: Converting NSDate to NSString causes unrecognized selector exception 2 answers I have an NSDictionary that holds a date like this: "2015-05-23 21:04:11 +0000" and I'm trying to parse it like: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss z"]; NSDate *date...

Getting timezone offset from a date string

objective-c,nsdate,nsdateformatter
I have the following date as a string: 2015-04-18T08:35:00.000+03:00 and I would like to get an offset from the GMT in seconds, i.e. 10800. I can split the date string by '+' character, have a string xy:ab and then calculate the offset with formula xy*3600 + a*60 + b. Is...

Have troubles with NSDateFormatter while parsing

objective-c,nsdateformatter
Here is the date sample: Wed, 13 May 2015 16:10:00 CEST My formatter aint working @"EEE, dd MMM yyyy HH:mm:ss vvvv" What should i change? UPD: full code NSString* formattedDayWithString(NSString* date){ NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init]; NSLocale *locale = [NSLocale currentLocale]; NSString *localeId = [locale displayNameForKey:NSLocaleIdentifier value:[locale localeIdentifier]]; SLog(@"%@...

Using dateFromString api of date formatter in a for loop giving huge memory issues

ios,objective-c,nsdate,nsdateformatter
I created an instance of NSDateFormatter outside the for loop( or can say an instance variable) and then used it in a for loop as [dateFormatter dateFromString]. This is giving me huge memory issues. I tried lowering the huge memory allocations using the @autorelease directive where I have moved the...

parsing the date and getting the day off by 1, nsdate

ios,objective-c,nsdate,nsdateformatter,nsdatecomponents
There are two ending days like beloew A = 2029-12-31T00:00:00+00:00 B = 2029-12-31T12:00:00+00:00 I am getting the month, day and year by following NSDateFormatter *endDateFormatter = [[NSDateFormatter alloc] init]; [endDateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate *endDate = [endDateFormatter dateFromString:self[@"license"][@"endDate"]]; NSDateComponents *endDatecomponents = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:endDate]; This is what...

Using NSTimeInterval after using dateFromString

swift,date,nsdate,nsdateformatter,nstimeinterval
I am working in swift and I am having trouble with NSDateFormatter and NSTimeInterval. What I am trying to do is save a string representation of a date, then later convert it back to an NSDate object and then find the time interval between that date and the current time....

String to NSdate not working

ios,nsdate,nsdateformatter
I want to convert the string 3/12/15 to NSdate. And i am using the below code. But after converting, the date becomes 2015-03-11 18:00:00 +0000. But i want the same format just like it is now in string. Any kind of help would be very appreciative. NSDateFormatter *df = [[NSDateFormatter...

How to subtract time from NSDate with the help of NSDateFormatter?

ios,objective-c,nsdate,nsdateformatter
I'm working on an application in which user set a time to do a task and before 10 or 15 minutes application triggers an alarm. Just like a reminder app you can say. After searching a lot on stackOverFlow and other different links my problem still exists. Here is what...

objective c - NSDateFormatter incorrect output [duplicate]

objective-c,xcode,nsdate,nsdateformatter
This question already has an answer here: returns a date an hour in the future 1 answer Why does the below code output the incorrect Date after conversion? NSString *customDate = @"23-06-1993"; NSLog(@"Custom Date: %@", customDate); NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"dd-MM-yyyy"]; NSDate *birthDayDate = [formatter dateFromString:customDate];...

Objective-C: What is the date format for a date like 2014-02-02T20:55:31.555Z

ios,objective-c,cocoa,nsdate,nsdateformatter
I'm trying to use NSDateFormatter to translate date strings I'm getting back in JSON. An example of such a date is 2014-02-02T20:55:31.555Z. I cannot, however, figure out what the correct date format is. I thought this would be it: yyyy-MM-dd'T'HH:mm:sss'Z' - no luck.

Nsdateformatter with nsdate for getting exact date in iOS

ios,nsdateformatter
I want to get the date from xml data ,which is in a string like as given below "Fri, 06 Feb 2015 11:25:00 -0600" how can i set the nsdateformatter for this type of date " -0600 is the time zone". Please help me

Converting different strings to NSDate - 1 is correct, the 2nd is a duplicate of the 1st

objective-c,nsdate,nsdateformatter,ios8.1
For some reason, this code is not converting the second string correctly; this is the code: NSLog(@"\n\nsearchStartTime: %@ searchEndTime: %@",searchStartTime, searchEndTime); [dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm a"]; startDate = [dateFormatter dateFromString:searchStartTime]; endDate = [dateFormatter dateFromString:searchEndTime]; NSLog(@"\n\nstartDate: %@ endDate: %@", startDate, endDate); This the definition and value of the searchStartTime and searchEndTime:...

Modify date format of a string

swift,nsdateformatter
I'm trying to modify the date format of a string in Swift. I need to print my date to the french format : 17 mai 2015 I tried this : var myDate = "2015-05-17 13:00:00" var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "d MMMM" var readableDate = dateFormatter.dateFromString(myDate) println("Readable date =...

NSDateFormatter time format depending on Locale

ios,swift,nsdateformatter
I'm experiencing a really strange issue that sounds more like a system bug. I want to format a date using only Hour and Minute information and, if necessary, display AM/PM. Here is my code: extension NSDate { func localizedStringTime()->String { let dateFormatter = NSDateFormatter() dateFormatter.locale = NSLocale.currentLocale() dateFormatter.dateFormat = "HH:mm"...

iOS: dateformatter in swift return nil

ios,swift,nsdateformatter
I have this code in my app service.requestLastDate{ (response) -> () in var str = response as NSString var d = str.stringByReplacingOccurrencesOfString("\"", withString: "") println("D \(str)") // D 2015-05-25 08:13:33 var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm" var date_formatted = dateFormatter.dateFromString(d) println("DATE FORMATTED \(date_formatted)") // is NIL with this...

Converting A NSDate Array to a String Array in Swift

string,swift,parse.com,nsdateformatter
I am a bit new to swift and IOS coding. I have a NSdate array which is retrieved from parse "CreatedAt" column. I need to convert that array to a string array so I can use it as an input for a text label in tableview cells. //I try the...

Swift Date Formatting

swift,nsdateformatter
Ok. This one has me perplexed. I'm trying to pull a date string from a button and format is as a date to be store in CoreData. Here is my code: let dateStr = setDateBTN.titleLabel?.text let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MM-dd-YYYY" let date:NSDate = dateFormatter.dateFromString(dateStr!)! If I do a...

Trouble With NSDateFormatter TimeZone Format

ios,xcode,nsdateformatter
I have a time stamp that looks like this... 2015-02-04T01:02:27.363Z Im using this but it doesn't work... [formatter setDateFormat:@"yyyy-MM-ddThh:mm:ss.ZZZZ"]; Ive tried a few different things but I don't quite understand the formatting of timezones. Can someone point out what the proper format is for a date like this? Thanks...

Localized NSDateFormatter

ios,objective-c,nsdateformatter
With help from some answered questions from others here I managed to get my NSDateFormatter working with strings in a different locale. Currently my code is the following: dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]]; [dateFormatter setDateFormat:@"MMM dd, yyyy HH:mm:ss a"]; //myDate = [[NSDate alloc] init]; --- unnecesary as...

nsdateformatter — convert string to date

ios,objective-c,nsdateformatter
I can't seem to get this right. here is the original value I am receiving... sDateOG NSString * @"2015-02-24T11:06:10.847-05:00" 0x7cd09580 I am trying to turn that into nice and clean date/timestamp. Still new at this, but what I thought was I should change this to a NSDATE, then I have...

Converting string to date with NSDateFormatter

ios,objective-c,nsstring,nsdateformatter
Im trying to convert this string '2015-05-08T09:44:25.343' format to date 'dd/MM/YYYY' format What I`m doing wrong? my date comes Nil. // convert 2015-05-08T09:44:25.343 to dd/MM/yyyy NSString *str = @"2015-05-08T09:44:25.343"; NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init]; [dateFormat setDateFormat:@"dd/MM/yyyy"]; NSDate *date = [dateFormat dateFromString:str]; NSLog(@"%@",date); NSString *convertedString = [dateFormat stringFromDate:date]; NSLog(@"%@", convertedString); ...

String to NSdate returns nil

ios,swift,datetime,nsdateformatter
I want to separate my String dateTime to different variables date and time because I will display it separately. How could I do this? Here's my code in getting the date only and it returns nil: let datetime = "2015-04-06T13:24:11.913" var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MMM-DD-YYYY" let date =...

Getting back a date from a string

ios,swift,nsdateformatter
im dealing with dates, and i'm having problems getting my date back from a string, i simplified my problem here: let date = NSDate() let formatter = NSDateFormatter() formatter.dateFormat = "dd-MM-YYYY" formatter.stringFromDate(date) formatter.dateFromString(formatter.stringFromDate(date)) And the output is: "25-05-2015" (Which is fine) "Dec 21, 2014, 12:00 AM" (???)...