Skip navigation.
 
mlRe: Getting an era's beginning date
FROM : Christopher Nebel
DATE : Tue Jan 29 22:17:23 2008

On Jan 28, 2008, at 8:31 PM, Nick Zitzmann wrote:

> On Jan 28, 2008, at 9:11 PM, Christopher Nebel wrote:
>

>> Realistic or not, they did it. =)  I think the Japanese calendar 
>> support was added in Tiger; the era names go back to Taika in 645 
>> AD.  I found that I can get at least the year by using something 
>> like this:
>>
>>     jp = [[NSCalendar alloc] initWithCalendarIdentifier:@"japanese"];
>>     components = [NSDateComponents alloc] init];
>>     [components setEra:235]; // Heisei; Taika is 0.
>>     date = [jp dateFromComponents: components]; // date is 1989-01-01 
>> 00:00:00 -0800
>>
>> Notice, however, that the day is wrong.  I don't know if that's a 
>> deficiency in my code or in the era data itself.

>
> The date is actually correct. This is why I wanted to know the 
> method of getting an era's beginning date, because eras, unlike 
> years, months, and days, can begin and end at any time on a calendar.
>
> In the case of the Japanese calendar, the 235th era is indeed the 
> Heisei era, but since you didn't specify year & date components, 
> NSCalendar assumes you meant the first year/month/day in that time 
> frame. The first year of the Heisei era is 1989, but January 1, 1989 
> is actually in the Showa (234th) era.


I guess I shouldn't have said "wrong", but rather "not what we 
wanted." =)  With a bit more experimentation, I established that Mac 
OS does in fact know the precise date of the era change -- getting the 
era for January 8, 1989 tells me 235 (Heisei), but for January 7, it's 
234 (Showa).  How to get NSCalendar (or whoever) to return that date, 
however, escapes me.


--Chris Nebel

Related mailsAuthorDate
mlGetting an era's beginning date Nick Zitzmann Jan 29, 00:49
mlRe: Getting an era's beginning date ? ?? Jan 29, 01:39
mlRe: Getting an era's beginning date Clark Cox Jan 29, 01:45
ml[WORKAROUND] Re: Getting an era's beginning date Nick Zitzmann Jan 29, 02:54
mlRe: Getting an era's beginning date Christopher Nebel Jan 29, 05:11
mlRe: Getting an era's beginning date Nick Zitzmann Jan 29, 05:31
mlRe: Getting an era's beginning date ? ?? Jan 29, 06:01
mlRe: Getting an era's beginning date Christopher Nebel Jan 29, 22:17
mlRe: Getting an era's beginning date Chris Kane Feb 1, 19:41