nsdatecomponents

I want to get a quarter value in NSDateComponents class

房东的猫 提交于 2019-11-26 18:34:38
问题 I want to get a quarter value from specified date. (*date variable) So. I have made following code and run. but, quarter value is zero. Why quarter value is zero? where's problem? Please advice from advanced man. NSDateComponents *comp1 = [[NSDateComponents alloc] init]; [comp1 setYear:2012]; [comp1 setMonth:6]; [comp1 setDay:1]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *date = [gregorian dateFromComponents:comp1]; <== want to get a

I want to get a quarter value in NSDateComponents class

谁说我不能喝 提交于 2019-11-26 17:26:05
问题 I want to get a quarter value from specified date. (*date variable) So. I have made following code and run. but, quarter value is zero. Why quarter value is zero? where's problem? Please advice from advanced man. NSDateComponents *comp1 = [[NSDateComponents alloc] init]; [comp1 setYear:2012]; [comp1 setMonth:6]; [comp1 setDay:1]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *date = [gregorian dateFromComponents:comp1]; <== want to get a

Differences in NSDateComponents syntax?

雨燕双飞 提交于 2019-11-26 15:32:06
I have been working on a clock app in Swift and with Xcode 6.3.2 the following code builds and runs just fine. // Get current time let date = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond | .CalendarUnitNanosecond, fromDate: date) let hour = components.hour % 12 let minute = components.minute let second = components.second let nanosecond = components.nanosecond However when I load the same project up in Xcode 7.0 beta and make no changes whatsoever, I get an error on the calendar

All dates between two Date objects (Swift)

∥☆過路亽.° 提交于 2019-11-26 14:39:30
I’m creating a date using NSDateComponents() . let startDate = NSDateComponents() startDate.year = 2015 startDate.month = 9 startDate.day = 1 let calendar = NSCalendar.currentCalendar() let startDateNSDate = calendar.dateFromComponents(startDate)! ... now I want to print all dates since the startDate until today, NSDate() . I’ve already tried playing with NSCalendarUnit , but it only outputs the whole difference, not the single dates between. let unit: NSCalendarUnit = [.Year, .Month, .Day, .Hour, .Minute, .Second] let diff = NSCalendar.currentCalendar().components(unit, fromDate:

Calculate age from birth date using NSDateComponents in Swift

让人想犯罪 __ 提交于 2019-11-26 09:41:01
问题 I am trying calculate the age from birthdayDate in Swift with this function: var calendar : NSCalendar = NSCalendar.currentCalendar() var dateComponentNow : NSDateComponents = calendar.components( NSCalendarUnit.CalendarUnitYear, fromDate: birthday, toDate: age, options: 0) But I get an error Extra argument toDate in call In objective c this was the code, but I don\'t know why get this error: NSDate* birthday = ...; NSDate* now = [NSDate date]; NSDateComponents* ageComponents = [[NSCalendar

Differences in NSDateComponents syntax?

南楼画角 提交于 2019-11-26 04:28:31
问题 I have been working on a clock app in Swift and with Xcode 6.3.2 the following code builds and runs just fine. // Get current time let date = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond | .CalendarUnitNanosecond, fromDate: date) let hour = components.hour % 12 let minute = components.minute let second = components.second let nanosecond = components.nanosecond However when I load the

NSDate get year/month/day

给你一囗甜甜゛ 提交于 2019-11-26 01:10:09
问题 How can I get the year/month/day of a NSDate object, given no other information? I realize that I could probably do this with something similar to this: NSCalendar *cal = [[NSCalendar alloc] init]; NSDateComponents *components = [cal components:0 fromDate:date]; int year = [components year]; int month = [components month]; int day = [components day]; But that seems to be a whole lot of hassle for something as simple as getting a NSDate \'s year/month/day. Is there any other solution? 回答1: