nsdateformatter

NSDate returning nil for the NSDateFormatter set correctly

时光怂恿深爱的人放手 提交于 2019-12-12 06:32:49
问题 I am getting the date in NSString format as mentioned below. Input:datestring = 30/04/2013 04:49 PM I am applying the format for NSDateformatter as mentioned below to convert this NSString to NSDate . Format:dateFormat= dd/MM/yyyy hh:mm a I still get the date conversion to Nil. Please help as I am not understanding this issue.Here is my code snippet to explain what i am doing in the utility function. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat

Why create Date from String only failed On Real iphone?

旧街凉风 提交于 2019-12-12 06:27:55
问题 I'm using following function to create Date from String. It works well on simulator. But it crashed on real iPhone. String: "Tue May 23 23:19:41 +0800 2017" The first picture is debugging information on real iPhone. The second one is debugging information on simulator. func createDate(fromString string: String) -> Date { let formatter = DateFormatter() formatter.dateFormat = "EEE MMM dd HH:mm:ss zzz yyyy" let date = formatter.date(from: string) //fatal error: unexpectedly found nil while

How to parse a UTC epoch 1352716800 to NSDate?

孤者浪人 提交于 2019-12-12 04:46:11
问题 I'm reading data from a XML file which has a UTC date looking like "2011-05-04T00:00:00", and a UTC epoch looking like 1352716800. Parsing the UTC epoch to NSDate would probably be much safer than messing around with a complex date format. How would I parse the UTC epoch to NSDate? With NSDateFormatter and a special format for "UTC Epoch"? I think that it is [[NSDate alloc] initWithTimeIntervalSince1970:epoch] and a test seemed to work. But I am not sure if that's just correct by accident or

dateFromString returns nil after using rfc3339dateFormatter as an example in iOS Documentation

自古美人都是妖i 提交于 2019-12-12 04:44:41
问题 I am trying to get NSDate from NSString by parsing in following manner: NSDateFormatter *rfc3339DateFormatter = [[NSDateFormatter alloc] init]; NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [rfc3339DateFormatter setLocale:enUSPOSIXLocale]; [rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; [rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; NSString *createdString = [NSString stringWithFormat:@"2014-08

iOS NSDateFormatter dateFromString returns nil only in one instance

心不动则不痛 提交于 2019-12-12 04:44:26
问题 Does NSDateFormatter have a propensity for unexpectedly returning nil? I wouldn't think it did. I am hoping that I have overlooked some miniscule detail which for whatever reason I cannot see. I have some data describing the sun and moon. It's listed below. I also have a loop which iterates over this data once it is loaded from its plist into a dictionary. Finally I have a class which processes dates for me using NSDateFormatter as a singleton. This process has worked pretty well and these

Convert string to date with timezone

你离开我真会死。 提交于 2019-12-12 04:33:05
问题 i have date string 2017-01-03T10:45:00.000+02:00 and I need to transfer it to something like this 2017-01-03 10:45:00 +0200 let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" // this formatter returning 2017-01-03 08:45:00 +0000 but I need // 2017-01-03 10:45:00 +0200 Thank you for your help! 回答1: Try this, Swift 3.0 let dateStr = "2017-01-03T10:45:00.000+02:00" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd\'T\'HH:mm:ss\'.000\'z"

Convert date string to NSDate

早过忘川 提交于 2019-12-12 03:46:27
问题 I've this string: "2016-10-08 00:20:00.000000". And I need it as an NSDate (Date for swift 3) object. I've tried with the following: let formatterJsonDate = DateFormatter() formatterJsonDate.dateFormat = "yyy-MM-dd hh:mm:ss" print(formatterJsonDate.date(from: "2016-10-08 00:20:00.000000")) I always return nil value. What's wrong? I guess it's something about the date format. 回答1: Your date format and your time string should be same. In your case it should be like, let formatterJsonDate =

Date Conversion and date difference issue in swift

你说的曾经没有我的故事 提交于 2019-12-12 03:37:38
问题 In one of my app I have date and time for multiple data fetching from server. I have shown this in tableview. Now from this I have to find some idle time for particular row by some condition by previous and next row's date and time difference. Something like departure and arrival of vehicle and idle time in between. I will show you the issued code where the issue occurs (only for I have both valid date). let dFormater = NSDateFormatter() dFormater.dateFormat = "ddMMMYYHHmm" dFormater.locale =

iPhone: Issue comparing a date between current date and sixty days from current date

烈酒焚心 提交于 2019-12-12 03:16:10
问题 I need to check an event date, which should be between Current date and 60 days from now. The below code is used, but it is NOT working correctly. Please note, i'm getting event string like this - "2012-04-14T16:50:02Z" from my server. // current date double currDateInMilliSecs = [NSDate timeIntervalSinceReferenceDate] * 1000; NSLog(@"currDateInMilliSecs: %f", currDateInMilliSecs); // sixty days double sixtydaysvalue = 60.0 * 24.0 * 3600.0 * 1000.0; NSLog(@"sixtydaysvalue: %f", sixtydaysvalue

NSDateFormatter:IST not recognised

烈酒焚心 提交于 2019-12-12 02:32:28
问题 IST timezone is not recognised by NSDateFormatter. Following date is recognised let dateString = "Jun 10, 2015 @ 12.30 AM PDT" let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MMM-dd-yyyy @ hh-mm-a-zzz" let date = dateFormatter.dateFromString(dateString) but time with IST timezone is not recognised. let dateString = "Jun 10, 2015 @ 12.30 AM IST" let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MMM-dd-yyyy @ hh-mm-a-zzz" let date = dateFormatter.dateFromString