NSCalendar date error

后端 未结 4 1779
面向向阳花
面向向阳花 2021-01-06 23:28

I\'m trying to use NSCalendar with NSIslamicCalendar identifier. But the day result is not good, her\'s my code:

NSCalendar *calanda         


        
4条回答
  •  不要未来只要你来
    2021-01-07 00:20

    datee = 1434-02-27 23:19:16 +0000 maybe this is a specialty of the islamic calendar? as in Islam the times of prayers are related to the sunrise equation it could try to express the sun time on a certain point. i.E. in Saudi Arabia the Sun time is the only valid time for religious reasons. they refuse to give the same land one time. If the sun is at the highest point, it is 12:00. as this differs a lot in cities just few hundred kilometers apart, the cities of Saudi Arabia have different times.

    Note, that although in any other islamic country normal timezones are used, this implementation would make sense, as probably the most valid use case for the islamic calendar are calculation of religious events — and it becomes much easier, if I use Sun time.


    With this code

        NSCalendar *islamicCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCalendar];
    
         NSDate *today = [NSDate date];
        [islamicCalendar rangeOfUnit:NSDayCalendarUnit startDate:&today interval:NULL forDate:today];
    
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setCalendar:islamicCalendar];
        [dateFormatter setTimeStyle:NSDateFormatterFullStyle];
        [dateFormatter setDateStyle:NSDateFormatterFullStyle];
    
        //english output 
        dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    
        NSString * islamicDateString = [dateFormatter stringFromDate:today];
        NSLog(@"%@", islamicDateString);
    

    it results in

    2013-01-11 01:13:46.110 islamicCalendarTest[18346:303] Friday, Safar 29, 1434 12:00:00 AM Central European Standard Time
    

    NSDateFormatter takes in account your default timezone.

提交回复
热议问题