Showing posts with label gregorianStartDate. Show all posts
Showing posts with label gregorianStartDate. Show all posts

Friday, May 10, 2013

NSDateFormatter gregorianStartDate example ios


gregorianStartDate

Returns the start date of the Gregorian calendar for the receiver.
- (NSDate *)gregorianStartDate
Return Value
The start date of the Gregorian calendar for the receiver.
Example of [NSDateFormatter gregorianStartDate]
CFGregorianDate gregorianStartDate, gregorianEndDate;
    CFGregorianUnits startUnits = {-10, 0, 0, 0, 0, 0};
    CFGregorianUnits endUnits = {10, 0, 0, 0, 0, 0};
    CFTimeZoneRef timeZone = CFTimeZoneCopySystem();

    gregorianStartDate = CFAbsoluteTimeGetGregorianDate(
                                                        CFAbsoluteTimeAddGregorianUnits(CFAbsoluteTimeGetCurrent(), 
                                                        timeZone, 
                                                        startUnits),
                                                        timeZone);
    gregorianStartDate.hour = 0;
    gregorianStartDate.minute = 0;
    gregorianStartDate.second = 0;

    gregorianEndDate = CFAbsoluteTimeGetGregorianDate(
                                                      CFAbsoluteTimeAddGregorianUnits(CFAbsoluteTimeGetCurrent(), 
                                                      timeZone,
                                                      endUnits),
                                                      timeZone);
    gregorianEndDate.hour = 0;
    gregorianEndDate.minute = 0;
    gregorianEndDate.second = 0;

    NSDate* startDate =
    [NSDate dateWithTimeIntervalSinceReferenceDate:CFGregorianDateGetAbsoluteTime(gregorianStartDate, timeZone)];
    NSDate* endDate =
    [NSDate dateWithTimeIntervalSinceReferenceDate:CFGregorianDateGetAbsoluteTime(gregorianEndDate, timeZone)];

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]autorelease];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]autorelease];
[dateFormatter setLocale:usLocale];