中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

NSDate 日期操作工具類(lèi)

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
    //  
    //  main.m  
    //  OC05-task-06  
    //  
    //  Created by Xin the Great on 15-1-26.  
    //  Copyright (c) 2015年 Xin the Great. All rights reserved.  
    //  
      
    #import <Foundation/Foundation.h>  
      
    int main(int argc, const charchar * argv[]) {  
        @autoreleasepool {  
            // insert code here...  
            //////////////////////NSDate --- 日期//////////////////////  
              
            //獲取當(dāng)前系統(tǒng)的時(shí)間   標(biāo)準(zhǔn)時(shí)間 GMT  格林尼治時(shí)間  
            NSDate *date = [NSDate date];  
            NSLog(@"date is %@", date);  
              
            NSDate *date1 = [[NSDate alloc] init];  
            NSLog(@"date1 is %@", date1);  
              
            //獲取時(shí)間戳   以秒為單位  
            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);  
              
            //獲取昨天的時(shí)間  
            NSTimeInterval second = 224 * 660 * 60;  
            NSDate *yesterDayDate = [[NSDate alloc] initWithTimeIntervalSinceNow:-second];  
            NSLog(@"yesterDayDate is %@",yesterDayDate);  
              
            //獲取明天的時(shí)間  
            NSDate *tomorrowDayDate = [NSDate dateWithTimeInterval:second sinceDate:[NSDate date]];  
            NSLog(@"tomorrowDayDate is %@", tomorrowDayDate);  
              
            //獲得未來(lái)的某一個(gè)時(shí)間  
            NSDate *future = [NSDate distantFuture];  
            NSLog(@"future is %@", future);  
              
            //獲得古代的某一個(gè)時(shí)間  
            NSDate *past = [NSDate distantPast];  
            NSLog(@"past is %@", past);  
              
            //日期的比較  
    //        BOOL isTure = [date isEqualToDate:date1];  
    //        NSLog(@"isTure is %d", isTure);  
              
            //返回兩個(gè)時(shí)間比較早的那個(gè)時(shí)間  
            NSDate *earlierDate = [tomorrowDayDate earlierDate:future];  
            NSLog(@"earlierDate is %@", earlierDate);  
              
            //返回兩個(gè)時(shí)間比較晚的那個(gè)時(shí)間  
            NSDate *later = [tomorrowDayDate laterDate:future];  
            NSLog(@"later is %@", later);  
              
              
            //將時(shí)間戳轉(zhuǎn)換成字符串  
            NSString *str = @"123456789";  
            NSTimeInterval second2 = [str doubleValue];  
            NSDate *date3 = [NSDate dateWithTimeIntervalSince1970:second2];  
            NSLog(@"date3 is %@", date3);  
              
            //格式化日期類(lèi)  
            NSDateFormatter *df = [[NSDateFormatter alloc] init];  
            [df setDateFormat:@"yyyy年MM月dd日 HH小時(shí)mm分鐘ss秒 ZZZZ"];  
              
            //將日期按照格式化日期類(lèi)轉(zhuǎn)換為字符串  
            NSString *str2 = [df stringFromDate:date3];  
            NSLog(@"str2 is %@", str2);  
              
            //通過(guò)字符串轉(zhuǎn)換為date  
            NSDate *date4 = [df dateFromString:str2];  
            NSLog(@"date4 is %@", date4);  
              
        }  
        return 0;  
    }  

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:Java 的 Cookie 處理類(lèi)

下一篇:使用 Arrays.copyOf 進(jìn)行數(shù)組復(fù)制