//
// main.m
// OC05-task-06
//
// Created by Xin the Great on 15-1-26.
// Copyright (c) 2015Äê Xin the Great. All rights reserved.
//
#import
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
//////////////////////NSDate --- ÈÕÆÚ//////////////////////
//»ñÈ¡µ±Ç°
ϵͳµÄʱ¼ä ±ê׼ʱ¼ä GMT ¸ñÁÖÄáÖÎʱ¼ä
NSDate *date = [NSDate date];
NSLog(@"date is %@", date);
NSDate *date1 = [[NSDate alloc] init];
NSLog(@"date1 is %@", date1);
//»ñȡʱ¼ä´Á ÒÔÃëΪµ¥Î»
NSTimeInterval time1970 = [date timeIntervalSince1970];
NSLog(@"time1970 is %.1f", time1970);
NSTimeInterval time2001 = [date timeIntervalSinceReferenceDate];
NSLog(@"time2001 is %.1f", time2001);
NSTimeInterval time = [date timeIntervalSinceNow];
NSLog(@"time is %.1f", time);
//»ñÈ¡×òÌìµÄʱ¼ä
NSTimeInterval second = 24 * 60 * 60;
NSDate *yesterDayDate = [[NSDate alloc] initWithTimeIntervalSinceNow:-second];
NSLog(@"yesterDayDate is %@",yesterDayDate);
//»ñÈ¡Ã÷ÌìµÄʱ¼ä
NSDate *tomorrowDayDate = [NSDate dateWithTimeInterval:second sinceDate:[NSDate date]];
NSLog(@"tomorrowDayDate is %@", tomorrowDayDate);
//»ñµÃδÀ´µÄijһ¸öʱ¼ä
NSDate *future = [NSDate distantFuture];
NSLog(@"future is %@", future);
//»ñµÃ¹Å´úµÄijһ¸öʱ¼ä
NSDate *past = [NSDate distantPast];
NSLog(@"past is %@", past);
//ÈÕÆÚµÄ±È½Ï
// BOOL isTure = [date isEqualToDate:date1];
// NSLog(@"isTure is %d", isTure);
//·µ»ØÁ½¸öʱ¼ä±È½ÏÔçµÄÄǸöʱ¼ä
NSDate *earlierDate = [tomorrowDayDate earlierDate:future];
NSLog(@"earlierDate is %@", earlierDate);
//·µ»ØÁ½¸öʱ¼ä±È½ÏÍíµÄÄǸöʱ¼ä
NSDate *later = [tomorrowDayDate laterDate:future];
NSLog(@"later is %@", later);
//½«Ê±¼ä´Áת»»³É×Ö·û´®
NSString *str = @"123456789";
NSTimeInterval second2 = [str doubleva lue];
NSDate *date3 = [NSDate dateWithTimeIntervalSince1970:second2];
NSLog(@"date3 is %@", date3);
//¸ñʽ»¯ÈÕÆÚÀà
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyyÄêMMÔÂddÈÕ HHСʱmm·ÖÖÓssÃë ZZZZ"];
//½«ÈÕÆÚ°´ÕÕ¸ñʽ»¯ÈÕÆÚÀàת»»Îª×Ö·û´®
NSString *str2 = [df stringFromDate:date3];
NSLog(@"str2 is %@", str2);
//ͨ¹ý×Ö·û´®×ª»»Îªdate
NSDate *date4 = [df dateFromString:str2];
NSLog(@"date4 is %@", date4);
}
return 0;
}