新聞中心
NSDate
創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的南縣網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
1.NSDate對象用來表示一個具體的時間點。
2.NSDate是一個類簇,我們使用的NSDate對象都是它的私有子類的實體。
3.NSDate存儲的是GMT時間,使用的時候會根據(jù) 當(dāng)前應(yīng)用 指定的 時區(qū) 進(jìn)行時間上的增減,以供計算或顯示。
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *now; NSDateComponents *comps = [[NSDateComponents alloc] init]; NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; now=[NSDate date]; comps = [calendar components:unitFlags fromDate:now]; NSInteger year = [comps year]; NSInteger month = [comps month]; NSInteger day = [comps day]; NSInteger hour = [comps hour]; NSInteger min = [comps minute]; NSInteger sec = [comps second]; NSLog(@"year:%ld \n \ month:%ld \n \ day:%ld \n \ hour:%ld \n \ min:%ld \n \ sec:%ld", year, month, day, hour, min, sec); //組裝 NSString *stringDate = [NSString stringWithFormat:@"%ld%ld%ld%ld%ld%ld", year, month, day, hour, min, sec ]; NSLog(@"stringDate:%@", stringDate);
獲取若干天前的日期:
NSTimeInterval secondsPerDay = 24 * 60 * 60;
for (int i = 0; i < 400; i++) {
NSDate *date = [[NSDate alloc] initWithTimeIntervalSinceNow:-i*secondsPerDay];
NSLog(@"%@", date);
}
當(dāng)前題目:IOS獲取當(dāng)前時間
標(biāo)題來源:http://fisionsoft.com.cn/article/joispc.html