English 中文(简体)
iPhone Date Picker rolls over to 2010 on December 27th?
原标题:

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date rolls over from December 26th to December 27th, the year changes to 2010.

I even rolled it forward to 2011... and it changes when December 25th changes to the 26th.... but wait... in 2012, it correctly rolls over on December 31 - January 1... and then its back to 29th-30th in 2013. Is there some kind of astronomical phenomenon I am not aware of going on or does Apple run on some crazy Heechee calendar I don t know of? The calendar app works correctly...

The most likely explanation is I am missing something so obvious that I will slap myself when I realize it. But hey, I haven t slept in... wow I don t remember if its been two days or three. Take pity and help me out here.

UPDATE: So maybe it wasn t something simple. Still looking for an answer here! Am I really the only person who has experienced this?? I ll bet when the end of December rolls around, more people will hit the same roadblock.

UPDATE2: Anyone? Still looking, still not finding...

UPDATE3: Still haven t found a solution. Come on! This is an interesting puzzle!

UPDATE4: Still no answer found. I have submitted the app and it is now in the appstore. Would still like to see this problem solved so I can update the app.

最佳回答

There may be this problem, that when you are on the last week of the month and the week has fewer than 7 days left in current month, then perhaps the API treated the week as the first week of the next month. Since december of 2012 has already 7 days in its last week there is no problem in that month.

I was getting the same problem here, and I solved it.

- (int) currentWeekOfMonth
{
    return CFCalendarGetOrdinalityOfUnit (
           CFCalendarCopyCurrent(),
           kCFCalendarUnitWeek,
           kCFCalendarUnitMonth,
           [self absoluteTime]);
}

my requirement is to show week number and for this i calculate the week number of first week of month and the add this to the total number of week in month.

int currentWeekNumberInYear =   [_calendarInfo currentWeekOfYear];
int currentWeekNumberInMonth = [_calendarInfo currentWeekOfMonth];
currentWeekNumberInYear = currentWeekNumberInYear-currentWeekNumberInMonth +1;
currentWeekNumberInYear = currentWeekNumberInYear<0 ? (NSInteger)[_calendarInfo weeksInMonth] ==5 ?49:48   : currentWeekNumberInYear;

I hope it will be useful to you.

问题回答

Turns out its the Date format string used to set up the NSDateFormatter that was causing this for me.

"yyyy" corresponds to the 4-digit year, while YYYY corresponds to the year starting from the Sunday of the 1st week of year. Why anyone would want this is anyone s guess, and it would really help if Apple provided a link to their list of format specifiers, but there you go.

Just make sure your format string has the year component in lowercase and it should be sorted.

This post on TUAW describes a similar problem in PhotoBooth on Mac OS X:

http://www.tuaw.com/2009/12/29/beware-photo-booth-time-stamps-its-a-bug-not-a-feature/

One commenter agrees with vikas that it s an end-of-week issue.





相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签