nscalendar

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

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

NSCalendar first day of week

Does anyone know if there is a way to set the first day of the week on a NSCalendar, or is there a calendar that already has Monday as the first day of the week, instead of Sunday. I'm currently working on an app that is based around a week's worth of work, and it needs to start on Monday, not Sunday. I can most likely do some work to w...

Creating a new NSCalendar calendar

I want to be able to convert between the Gregorian and Julian calendars (note: not "julian date") using NSCalendar on the iPhone. How can I subclass NSCalendar to use the Julian calendar? I want to do this without regards for 1582 or 1752 or any given year. ...

Is it possible to create an own calendar system in cocoa touch / UIKit?

There are some constants for NSLocale, like NSJapaneseCalendar, but what if I wanted to create a "Physical Calendar" or something that isn't there? Is there a way to define an arbitrary calendar system and then use that with NSDate, NSDateComponents and NSCalendar? ...

iPhone - How to return year as an integer from a given date?

Hi all, I'm trying to return the 4 digit year from any given date as an integer. I'm not strong with the NSCalendar or NSDate functions, but have tried using them with components from date and date formatters with no success. Thanks. ...

Getting first and last days of current week

How can I get first and last days of the current week? What I need is some way of filtering a set of objects with NSDate property to leave only ones, that appear on current week, and then filter them by days. Also I need some way to get localized day names. I've tried to play with NSCalendar, NSDate and NSDateComponents, but it seems th...

Does -[NSCalendar ordinalityOfUnit:inUnit:forDate:] not work?

I have the following code in my program: NSUInteger currentMinuteOrdinal = [[NSCalendar currentCalendar] ordinalityOfUnit:NSMinuteCalendarUnit inUnit:NSEraCalendarUnit forDate:[NSDate date]]; NSUInteger passedInMinuteOrdinal = [[NSCalendar currentCalendar] ordinalityOfUnit:NSMinuteCalendarUnit inUnit:NSEraCalendarUnit forDate:passedInDa...

NSCalendar: Problem getting weeks in a month...

I am creating a calendar control of sorts... One thing I need to know is how many weeks are there in a Month... So NSCalendar rangeOfUnit:inUnit:forDate Seems to be exactly what I need... Except I am noticing something that seems off and I can't quite figure out why this is happening... The following code... NSCalendar *calendar = [...

dateByAddingComponents problem and getting difference of dates with NSDateComponents problem!

I am having problems with adding values to dates and also getting differences between dates. The dates and components calculated are incorrect. So for adding, if I add 1.5 months, I only get 1 month, however if I add any whole number ie (1 or 2 or 3 and etc) it calculates correctly. Float32 addAmount = 1.5; NSDateComponents *component...

Working with NSCalendar -- getting the next first tuesday of a month

Hi all, This is a bit odd, but is it possible to use an NSCalendar (or any component, for that matter) to figure out what the date of the next "first tuesday of the month" would be? For example, today is Thursday March 25, 2010. The next "first tuesday of the month" would be on April 6. Likewise, if I were looking for the next "first...

iPhone OS: How do I create an NSDate for a specific date?

Seems like a simple thing but I can't seem to find a way to do it. It would be great to see a couple different methods. Thanks, Nick ...

iPhone NSDate eg. next Friday

Hello I want to create a function which results the date of next Friday but i've no plan how to do it. Has anyone a good hint to me ? Greets Simon ...

Removing time from date format

Hi, I am developing an application in that i have used DatePicker to pick the date but it gives me date with time .I have converted that format into string, now i just want date from that. How should i do that.Plz suggest me something. Following is my code Snippet. NSDate *selected =[datePicker date]; NSString *dateString = [NSSt...

Weird behavior when creating an NSDate of January the 1st and the 2nd

Hello, I'm creating a date like this : NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"YYYY"]; NSInteger year = [[dateFormatter stringFromDate:[NSDate date]] intValue]; NSLog(@"NSInteger YEAR : %...

NSDate/NSCalendar Issue

Hi, I have the following code in my app. Its an iPad app, with five tables in a single view named monTable, tueTable etc. These tables represent monday to friday. In this code I get the date and set each table title to the date monday to friday (this week). Then if I press a button nextWeek becomes TRUE and I reload table data. This the...

How to clear NSDate milliseconds

I want to keep date/times in a CoreData store with no seconds or milliseconds. (I'm doing some processing to round times off, and stray seconds/milliseconds become a monkey wrench.) It's easy enough to drop the seconds: NSDate *now = [NSDate date]; NSDateComponents *time = [[NSCalendar currentCalendar] compon...

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 = [co...

NSCalendar problem with BC era

Greetings, Recently I faced a big problem (as it seems to me) with NSCalendar class. In my task I need to work with a large time periods starting from 4000BC to 2000AD (Gregorian calendar). In some place I was forced to increment some NSDate by 100 year interval. When incrementing the years in AD timeline (0->...) everything worked fin...

NSDate for first day of the month

This is quite a simple concept, but as of yet I have been unable to find an elegant (and calendar locale independent) solution. I need to find the first day of the month for an arbitrary NSDate. For example, given an arbitrary NSDate (arbitraryDate) another NSDate object will be returned (let's call this firstDayOfMonthDate) which repres...

NSCalendar crashing app

Hi, I'm initializing a NSCalendar in viewDidLoad like this: gregorian = [NSCalendar currentCalendar]; The calendar is declared in the corresponding .h file like this: NSCalendar *gregorian; When accessing the calendar from a method my app crashes: - (void)someMethod{ unsigned int unitFlags; unitFlags = NSHourCalendarUnit | NS...