nsdate

warning no-method descriptionWithCalendarFormat:timeZone:locale found

人盡茶涼 提交于 2019-12-11 07:47:22
问题 I am getting this warning in xcode 3.1.3 iphone os 3.0. This method is also not available in the NSDate class. But I am getting the date from this method. Can anyone please tell me How can I get rid of this warning???? 回答1: You'll want to use NSDateFormatter instead. descriptionWithCalendarFormat:timeZone:locale: landed on the "non-public API" list recently, and is grounds for rejection of your app. Here's an example of how you can use NSDateFormatter: NSDateFormatter *dateFormatter = [

NSDateFormatter gives different output/wrong (GMT?) time

和自甴很熟 提交于 2019-12-11 07:39:59
问题 I have tried setting the timezone and locale of the NSDateFormatter but I can't seem to get anything to work. Here is the code NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"MM/dd/yyyy hh:mm:ss"]; NSString *myFireDateString=[@"9/17/11" stringByAppendingString:@" 09:00:00"]; NSDate *myFireDate = [dateFormat dateFromString:myFireDateString]; NSLog(@"The datestring is is %@",myFireDateString); NSLog(@"The formatted date is %@",myFireDate); Here is the

dateFromString working in ios 6 but not in ios 5

↘锁芯ラ 提交于 2019-12-11 06:33:31
问题 This code working on iOS 6.0 simulator, but not working on iOS 5.0 NSString *unformattedDate = @"2008-09-25T20:41:11.000+00:00"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"]; NSDate *dateFromString = [dateFormatter dateFromString:unformattedDate]; [dateFormatter setDateFormat:@"dd.MM.yy"]; NSLog(@"%@", [dateFormatter stringFromDate:dateFromString]); What can be wrong? 回答1: Since the ZZZZZ date format specifier

Assemble date object from integers?

孤者浪人 提交于 2019-12-11 06:18:44
问题 Given three integers, representing a day, month and year, what code would assemble those integers into a date object? 回答1: You should look at NSDateComponents : int y = 2011; int m = 1; int d = 15; NSDateComponents *dc = [[NSDateComponents alloc] init]; [dc setYear:y]; [dc setMonth:m]; [dc setDay:d]; NSLog(@"%@: %@", [[dc date] class], [dc date]); 回答2: NSDateFormatter uses the Unicode Standard for parsing date strings into dates. So, format your integers into a date string and then use and

Why date formatter crashes?

☆樱花仙子☆ 提交于 2019-12-11 06:08:33
问题 My below code is working fine. I don't know why it crashes sometimes(Mostly on application launch. 1 case out of ~100). extension Formatter { static let enUSPOSIX: DateFormatter = { let formatter = DateFormatter() formatter.locale = Locale(identifier: "en_US_POSIX")// return formatter }() } let dateFormatter = Formatter.enUSPOSIX dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss+hh:mm" let date = dateFormatter.date(from: "2018-05-13T00:00:00+05:30") dateFormatter.timeZone = TimeZone

iOS NSDateFormatter Timezone

蹲街弑〆低调 提交于 2019-12-11 05:59:22
问题 I have some code that takes a string, turns it into a date, reformats it then spits it out as another string: [formatter setDateFormat:@"YYYY'-'MM'-'DD','HH:mm:ss','ZZZ"]; [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"America/New_York"]]; NSDate *date = [formatter dateFromString:combinedString]; [formatter setDateStyle:NSDateFormatterLongStyle]; NSString *finishedString = [formatter stringFromDate:date]; Basically, it works fine except for the timezones. All of the input strings are

Cannot find the right date format (NSDateFormatter) for this

本小妞迷上赌 提交于 2019-12-11 05:57:19
问题 I cannot convert this kind of strings to NSDate, please help me out here. What am I doing wrong below? dateString = @"201302051614461"; NSDateFormatter *dateFormatter = [NSDateFormatter new]; [dateFormatter setDateFormat:@"YYYYMMddHHmmSSSSS"]; NSDate *date = [dateFormatter dateFromString:dateString]; NSLog(@"dateString: %@", dateString); NSLog(@"date: %@", date); This returns with an empty date. 回答1: If I break it like this 2013 02 05 16 14 46 1 Then the format string is @"yyyyMMddHHmmssS 回答2

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

Error in dateFormat returns nil

醉酒当歌 提交于 2019-12-11 05:41:41
问题 As an exercise to practice Objective-C, I am converting Swift code to Objective-C. After 1.5k lines converted, I find myself blocked for the past few days on one last issue. In a few cells of my TableViewController, the description labels don't appear at all. I checked my code, and it seems the strings that are passed to the cells are actually empty or nil. I seem to have made a syntax error in converting the Swift code that returns the date to my cells. What error have I made that makes the

Set the first of the month of a NSDate

懵懂的女人 提交于 2019-12-11 05:29:17
问题 I'm using a NSDate that is incremented/decremented thanks to NSDateCompoments: dateComponents = [[NSDateComponents alloc] init]; self.date = [gregorian dateByAddingComponents:dateComponents toDate:[NSDate date] options:0]; ... [dateComponents setDay:1]; self.date = [gregorian dateByAddingComponents:dateComponents toDate:self.date options:0]; [dateComponents setDay:0]; Now, I want to set the day to set the NSDate to the first of the month (and the first month of the year too), but I dont know