The time resolution of [C/OC something]NSDate and NSCalendar get date

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
 NSDate *now =[NSDate dateWithTimeIntervalSinceNow:8*60*60];//Because the calibration and our local date, so +8 hours.
        NSLog(@"%@",now);
        
        NSCalendar *calender = [NSCalendar currentCalendar];
        NSUInteger unitInteger = NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
        
        NSDateComponents *components = [calender components:unitInteger fromDate:now];
        //Get the date of the information, and then split
        NSInteger year = [components year];
        NSInteger month = [components month];
        NSInteger day = [components day];
        NSString *ymdDate = [NSString stringWithFormat:@"%lu-%lu-%lu",year,month,day];
        NSLog(@"%lu-%lu-%lu",year,month,day);

2.


For the method to create an instance of NSDate is

+ (id)date;

Returns the current time

+ (id)dateWithTimeIntervalSinceNow:(NSTimeInterval)secs;

Returns the current time as the benchmark, then after secs seconds

+ (id)dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)secs;

Return to 2001/01/01 GMT as the benchmark, then after secs seconds

+ (id)dateWithTimeIntervalSince1970:(NSTimeInterval)secs;

Return to 1970/01/01 GMT as the benchmark, then after secs seconds

+ (id)distantFuture;

Returned many years later, one day in the future.

For example, you need a than it is now (Now) late (large) very long time time value, you can call this method. Test the return 4000/12/31 16:00:00

+ (id)distantPast;

One day returns many years ago.

For example, you need a than it is now (Now) early (small) very long time time value, you can call this method. The test back to 0001 BC/12/31 17:00:00

For instance method to create the instance of NSDate is

- (id)addTimeInterval:(NSTimeInterval)secs;

Return to save the current instance at the time as reference, and then after secs seconds

For instance initialization method for NSDate instances of

- (id)init;

Initialization for the current time. like date method

- (id)initWithTimeIntervalSinceReferenceDate:(NSTimeInterval)secs;

Initialization to 2001/01/01 GMT as the benchmark, then after secs seconds. like dateWithTimeIntervalSinceReferenceDate: method

- (id)initWithTimeInterval:(NSTimeInterval)secs sinceDate:(NSDate *)refDate;

Initialize the refDate as a reference, and then after secs seconds

- (id)initWithTimeIntervalSinceNow:(NSTimeInterval)secs;

Initialization to current time as the benchmark, then after secs seconds

Comparison between the 2 date using the following method

- (BOOL)isEqualToDate:(NSDate *)otherDate;

Compared with otherDate, the same return YES

- (NSDate *)earlierDate:(NSDate *)anotherDate;

Compared with anotherDate, return to the earlier date

- (NSDate *)laterDate:(NSDate *)anotherDate;

Compared with anotherDate, the date back to late

- (NSComparisonResult)compare:(NSDate *)other;

The method for sorting when calling:

When the instance is preserved. The date value and anotherDate the same return NSOrderedSame

When the instance is preserved. The date value return NSOrderedDescending later than anotherDate

When the instance is preserved. The date value early to return to NSOrderedAscending anotherDate

3 reclaim time interval using the following method

- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)refDate;

Taking refDate as the reference time, return time and save the time interval of the refDate instance

- (NSTimeInterval)timeIntervalSinceNow;

At the current time (Now) as the reference time, the instance is returned to save time and current time interval (Now)

- (NSTimeInterval)timeIntervalSince1970;

Taking 1970/01/01 GMT as reference time, the instance is returned to save time and 1970/01/01 GMT interval

- (NSTimeInterval)timeIntervalSinceReferenceDate;

Taking 2001/01/01 GMT as reference time, the instance is returned to save time and 2001/01/01 GMT interval

+ (NSTimeInterval)timeIntervalSinceReferenceDate;

Taking 2001/01/01 GMT as reference time, returns the current time (Now) and 2001/01/01 GMT interval

The 4 time is expressed as a string

- (NSString *)description;

Using YYYY-MM-DD HH:MM:SS + HHMM representation of time.

The " ± HHMM" representation and existence of time how many minutes hours GMT difference. For example, if the time zone set up in Beijing, " ± HHMM" display; "+0800"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Merle at December 12, 2013 - 12:53 PM