Tag: nscalendar

iPhone NSDate eg. next Friday

I want to create a function which results the date of next Friday but I have no plan how to do it. Has anyone a good hint to me ?

How to find what day of the week for any given date using Cocoa

I’m trying to figure out what day (i.e. Monday, Friday…) of any given date (i.e. Jun 27th, 2009) Thank you.

Compare two NSDates for same date/time

This question already has an answer here: How to compare two dates in Objective-C 14 answers

how do I set an existing NSDate's time?

how do I set an existing NSDate‘s time? That is I have a date (say current date/time), but then want to set this to a specific time (e.g. 11.23am) say. What is the quickest way to do this in objective C? I’m looking at NSCalendar and see methods such as dateByAddingComponents:toDate:options:, and dateFromComponents:, but these […]

NSDate get year/month/day

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 […]

Sending NSCFCalendar nil NSDate Sarcastic Error

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:fromDate:toDate:options:]: fromDate cannot be nil I mean really, what do you think that operation is supposed to mean with a nil fromDate? An exception has been avoided for now. A […]

Swift – Get next date from a array of weekdays

Context I’m making an app where I have tasks with due dates and once they are done I want to set a new due date for according to a new date according to a day of the week repeat pattern chosen by the user. Im saving due dates as Date. Im saving the repeat pattern […]

How to convert from NSDate(timeIntervalSince1970 to NSDate()?

This is my code. But an error said, cannot invoke dateComponent with an argument list of type… let fromDate = NSDate(timeIntervalSince1970: TimeInterval(tweetsArray[indexPath.row].timestamp)!) let toDate = NSDate() let components : NSCalendar.Unit = [.second, .minute, .hour, .day, .weekOfMonth] let differenceOfDate = NSCalendar.current.dateComponents(components, from: fromDate, to: toDate)

Apple Swift: how to get current seconds in 1/100 or 1/1000?

func updateTime() { var date = NSDate() var calendar = NSCalendar.currentCalendar() var components = calendar.components(.CalendarUnitSecond, fromDate: date) var hour = components.hour var minutes = components.minute var seconds = components.second counterLabel.text = “\(seconds)” var myIndicator = counterLabel.text?.toInt() if myIndicator! % 2 == 0 { // do this } else { // do that } } I’d […]

Working out the start and end of a day. Swift

I have a function to work out the start and end of a week which works as expected. I want to implement another function which works out the start and end of a single day. I have the code below however I get the following error: Type of expression is ambiguous without more context. public […]