nscalendar

Swift - Check if date is in next week / month. ( isDateInNextWeek() isDateInNextMonth() )

不想你离开。 提交于 2019-12-04 19:32:21
We have those convenient functions in calendar: let calendar = NSCalendar.currentCalendar() calendar.isDateInToday(date) calendar.isDateInTomorrow(date) But I am missing those two: calendar.isDateInNextWeek(date) calendar.isDateInNextMonth(date) As @Rob mentioned, the meaning is: "in the calendar week starting this coming Sunday, going through the following Saturday" I having a hard time figuring out how to implement those functions in a robust way that covers all the corner cases. Can someone provide an assistant? The algorithm is not very spectacular: Calculate start of current week Use

UILocalNotification end date

孤人 提交于 2019-12-04 18:41:49
I wonder if it's possible to set end date for UILocalNotification ? I want my notification to fire everyday ( NSDayCalendarUnit ) but I have end date which I cannot cross (deadline) e.g. I'm taking a photo of my growing mustache everyday for one year period and after a year notifications won't be displayed. I hope you got my point of view... There is not such option in UILocalNotification as you can read in the documentation. Your only option is to check wether the year is over when every the user starts the app. In the UILocalNotification object, I'd recommend setting the repeatInterval

In Objective-C, to get the current hour and minute as integers, we need to use NSDateComponents and NSCalendar?

六月ゝ 毕业季﹏ 提交于 2019-12-04 07:05:40
I'd like to get the current hour and minute as integers. So if right now is 3:16am, I'd like to get the two integers: 3 and 16. But it looks like [NSDate date] will give the number of seconds since 1970, or it can give a string of the current time representation, but there is no easy way to get them as integers? I see a post in Getting current time , but it involved NSDateComponents and NSCalendar ? That's way too complicated... all that was need is something like NSDate *date = [NSDate date]; int hour = [date getHour]; // which is not possible Is there a simpler way than using 3 classes

NSCalendar NSDateComponents weekofYear return 1 with date 2014-12-31

隐身守侯 提交于 2019-12-04 06:38:42
问题 I want to get weekofYear with date '2014-12-31' ,but it always return 1 not 52 here is my code: NSCalendar *calendar = [NSCalendar currentCalendar]; NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit | NSWeekOfMonthCalendarUnit | NSWeekOfYearCalendarUnit; NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:[NSDate date]]; NSlog(@"%i",dateComponent

Sending NSCFCalendar nil NSDate Sarcastic Error [closed]

孤街浪徒 提交于 2019-12-04 04:53:51
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . A few threads here discuss the new iOS 6 Xcode error that pops up in the console when sending nil dates to Calendar methods: -[__NSCFCalendar components

How do I implement previous/next month buttons and show dates for current month?

耗尽温柔 提交于 2019-12-04 02:35:34
问题 Scenario: I have an expense tracking iOS Application and I am storing expenses from a expense detail view controller into a table view (with fetched results controller) that shows the list of expenses along with the category and amount and date. I do have a date attribute in my entity "Money" which is a parent entity for either an expense or an income. Question: What I want is to basically categorize my expenses on a monthly basis and display it as the section header title for example : (Nov

Cocoa get first day in week

早过忘川 提交于 2019-12-03 22:46:36
问题 How to get the first day of a week for a date this seems more easy at it is, since : when the week starts with sunday, i need to get back the sunday date if it starts on monday, i need to get the monday date the input date is any date in week with time... i tried several approaches, but the edge case make it difficould i made a function, which however doesn't work in 100% (not sure about the [components setDay: -weekday + 2];) - (NSDate *)firstDateOfWeek { NSCalendar * calendar = [NSCalendar

Creating a future date in swift with NSDate()

▼魔方 西西 提交于 2019-12-03 14:53:13
问题 I'm getting an error: "Missing argument for parameter 'coder' in call" for the following code: var components = NSDateComponents() components.setValue(1,forComponent: NSCalendarUnit.CalendarUnitMonth); var expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(components, toDate: NSDate(),options:0) The docs calls for: NSCalendar.currentCalendar().dateByAddingComponents(<#comps: NSDateComponents?#>, toDate: <#NSDate?#>, options: <#NSCalendarOptions#>) Can anyone see what I'm

Creating a future date in swift with NSDate()

天涯浪子 提交于 2019-12-03 04:34:59
I'm getting an error: "Missing argument for parameter 'coder' in call" for the following code: var components = NSDateComponents() components.setValue(1,forComponent: NSCalendarUnit.CalendarUnitMonth); var expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(components, toDate: NSDate(),options:0) The docs calls for: NSCalendar.currentCalendar().dateByAddingComponents(<#comps: NSDateComponents?#>, toDate: <#NSDate?#>, options: <#NSCalendarOptions#>) Can anyone see what I'm missing? I don't see a parameter named 'coder' required. holex how it looks to be with swift 4.x let date

How to get the 'n' weekday of a Date

最后都变了- 提交于 2019-12-02 12:35:07
I need to translate this function into swift. Basically what does it get the 'n' day of the current week. So for example if i use it with NSDate().getWeekDay(0) it gives me Sun 11 Sept, and so on. But seems rangeOfUnit no longer exists in Swift-3. This was my previous implementation in Swift-2 extension NSDate { func getWeekDay(day: Int) -> NSDate { var beginningOfWeek: NSDate? NSCalendar.currentCalendar().rangeOfUnit(NSCalendarUnit.WeekOfYear, startDate: &beginningOfWeek, interval: nil, forDate: self) let comps = NSDateComponents() comps.day = day comps.minute = NSCalendar.currentCalendar()