nsdateformatter

Specific date after number of dates

我们两清 提交于 2019-12-11 05:53:42
问题 Currently I'm working on NSDate and NSDateFormatter . My issue is I need to find the date after 100 days of the user specified date. Currently I'm using this hard-coded string for finding a future date. calendar.maximumDate = [self.dateFormatter dateFromString:@"20/08/2015"]; But it is not correct way and not work with user specified date. Is there anyway to achieve this ? Please help me. Thanks in advance. 回答1: Like this: // How much day to add int addDaysCount = 100; // Create and

NSDateFormatter not working

怎甘沉沦 提交于 2019-12-11 05:50:01
问题 Ok I feel kind of dumb asking this, but any idea why this is not working: { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"mmmm dd, yyyy"]; NSDate *myDateFromString = [formatter dateFromString:creditDate.text]; NSLog(@"%@", myDateFromString); [self.credit setCertificationDate: myDateFromString]; } It returns null 回答1: Format and string don't match because "m" is minute and "M" is month. So "August 18 2012" can't be interpreted, take "MMMM dd yyyy"

NSDateFormatter still parsing instead having incorrect format

烂漫一生 提交于 2019-12-11 05:41:08
问题 Having some problems parsing date. I have an array of supported formats and once I receive the date (string) from API, I try to parse it iterating through the formats until I get a valid NSDate object. A snippet from Xcode Playground -- let dateString = "02/06/1987" // --> want to parse into this Feb 6, not Jun 2 let dateFormatIncorrect = "dd.MM.yyyy" let dateFormatCorrect = "MM/dd/yyyy" let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = dateFormatIncorrect let date =

Swift 3 - UTC to time ago label, thinking 12h / 24h device time changes

≯℡__Kan透↙ 提交于 2019-12-11 04:36:28
问题 I want to convert timeUTC to "5s ago." ago label also thinking 12h / 24h changes on the phone. Because goes crash. Now below lines of code return label value what I want in the Playground. But not on my ios project. It doesn't go into If block. What I'm missing or What's the wrong with that? let dateStringUTC = "2016-10-22 12:37:48 +0000" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZ" if let from = dateFormatter.date(from: dateStringUTC) {

How to convert the date string into string( yyyy-MM-dd). While doing so, I getting null values?

岁酱吖の 提交于 2019-12-11 04:05:39
问题 I have the data as customerFromDate " 01 Apr 2010 " and customerToDate " 30 Apr 2010 " which is a string. I want to convert that format into the string "yyyy-MM-dd", but when doing so I got null values. Please see the following code which I had tried. printf("\n customerFromDate %s",[customerStatementObj.customerFromDate UTF8String]); printf("\n customerToDate %s",[customerStatementObj.customerToDate UTF8String]); /* prints as the following customerFromDate 01 Apr 2010 customerToDate 30 Apr

Get time from NSDate returns nil

时光毁灭记忆、已成空白 提交于 2019-12-11 04:04:14
问题 I am trying to show time on graph and i have a full time stamp in this @"2012-08-28 18:50:24" format. when i try to get time from this date then it returns nil in NSDate. NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss"]; NSDate *time = [formatter dateFromString:@"2012-08-28 18:50:24"]; in this code only if I change [formatter setDateFormat:@"HH:mm:ss"]; line to [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; then it starts working with full

Error combining NSCalendarUnit with OR (pipe) in Swift 2.0

末鹿安然 提交于 2019-12-11 03:51:21
问题 I have some code that's breaking in Swift 2.0: let formatter = NSDateComponentsFormatter() formatter.allowedUnits = NSCalendarUnit.Year formatter.allowedUnits |= .Month formatter.allowedUnits |= .WeekOfMonth formatter.allowedUnits |= .Day formatter.allowedUnits |= .Hour formatter.allowedUnits |= .Minute I get the error Binary operator '|=' cannot be applied to 'NSCalenderUnit' operands . What's the new way of doing this kinda thing? 回答1: NSCalendarUnit is an OptionSetType in Swift 2, instead

IOS NSDate from string with time only

有些话、适合烂在心里 提交于 2019-12-11 03:48:58
问题 My task is to parse string with time to NSDate. And I do it very well with following code: NSString* timeStr = @"15:00:00" NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]]; [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]]; [formatter setDateFormat:@"HH:mm:ss"]; NSDate* result = [formatter dateFromString:timeStr]; But as a result I get 2000-01-01 15:00:00 CET and I dont understand why

Still having NSDateFormatter result issues even with NSTimezone properly set, why?

吃可爱长大的小学妹 提交于 2019-12-11 02:05:03
问题 The result is still a day before, I'm just asking myself why, because the NSTimeZone is properly set and is the right one for my country (italy, rome) here's my stub of code, any ideas? NSString *dateString = @"03/07/2008"; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setFormatterBehavior:[NSDateFormatter defaultFormatterBehavior]]; [formatter setDateFormat:@"dd/MM/yyyy"]; [formatter setLocale:[NSLocale currentLocale]]; [formatter setTimeZone:[NSTimeZone

Converting string to date returning the day before

自作多情 提交于 2019-12-11 01:46:51
问题 I have a date in a string with this format "2017-03-14" (yyyy-MM-dd) and i am trying to convert it into a string with this format "Tuesday, March 14, 2017". This is my code: let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" let date = dateFormatter.date(from: "2017-03-14") Now if i print the value of "date", i get this: 2017-03-13 22:00:00 +0000 This is just the day before. Why is that ? EDIT: I need to compare date before formatting it. var newDateString : String =