時(shí)間格式化標(biāo)簽

常見(jiàn)的時(shí)間格式是 yyyy-MM-dd hh:mm:ss,下面文章介紹其他類型

原文:如有侵權(quán),回復(fù)告知后刪除
http://blog.csdn.net/macro_13/article/details/41850031?utm_source=tuicool&utm_medium=referral

//  
//  main.m  
//  時(shí)間格式化  
//  
//  Created by Macro on 14-12-10.  
//  Copyright (c) 2014年 Macro. All rights reserved.  
//  
  
#import <Foundation/Foundation.h>  
  
int main(int argc, const charchar * argv[]) {  
    @autoreleasepool {  
          
        //返回當(dāng)前時(shí)間,以GMT為準(zhǔn)  
        NSDate * date = [NSDate date];  
        NSLog(@"%@", date);  
          
        //顯示當(dāng)前時(shí)間距離1970-01-01 00:00:00的秒數(shù)  
        NSLog(@"%.2f", date.timeIntervalSince1970);  
          
        //從現(xiàn)在起3600秒時(shí)候的時(shí)間  
        NSLog(@"%@", [NSDate dateWithTimeIntervalSinceNow:3600]);  
          
        //1970-01-01 00:00:00前3600秒的時(shí)間  
        NSLog(@"%@", [NSDate dateWithTimeIntervalSince1970:-3600]);  
          
        //返回一個(gè)很久之后的時(shí)間  
        NSLog(@"%@", [NSDate distantFuture]);  
          
        //返回一個(gè)很久之前的時(shí)間  
        NSLog(@"%@", [NSDate distantPast]);  
          
        //返回當(dāng)前系統(tǒng)時(shí)區(qū)  
        NSLog(@"%@", [NSTimeZone systemTimeZone]);  
          
          
        //時(shí)間戳  格式化時(shí)間  
        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];  
        dateFormatter.dateFormat = @"G yyyy-MM-dd E D F w W a z hh:mm:ss.SSS";  
        NSString * dateStr = [dateFormatter stringFromDate:date];  
        NSLog(@"%@", dateStr);  
          
        /* 
         G 年代標(biāo)志符 
         y 年 
         M 月 
         d 日 
         h 時(shí) 在上午或下午 (1~12) 
         H 時(shí) 在一天中 (0~23) 
         m 分 
         s 秒 
         S 毫秒 
         E 星期 
         D 一年中的第幾天 
         F 一月中第幾個(gè)星期幾 
         w 一年中第幾個(gè)星期 
         W 一月中第幾個(gè)星期 
         a 上午 / 下午 標(biāo)記符  
         k 時(shí) 在一天中 (1~24) 
         K 時(shí) 在上午或下午 (0~11) 
         z 時(shí)區(qū) 
         */  
  
    }  
    return 0;  
} 
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容