美文网首页
时间格式化标签

时间格式化标签

作者: WeeverLu | 来源:发表于2016-06-07 11:38 被阅读17次

    常见的时间格式是 yyyy-MM-dd hh:mm:ss,下面文章介绍其他类型

    原文:如有侵权,回复告知后删除
    http://blog.csdn.net/macro_13/article/details/41850031?utm_source=tuicool&utm_medium=referral

    //  
    //  main.m  
    //  时间格式化  
    //  
    //  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 {  
              
            //返回当前时间,以GMT为准  
            NSDate * date = [NSDate date];  
            NSLog(@"%@", date);  
              
            //显示当前时间距离1970-01-01 00:00:00的秒数  
            NSLog(@"%.2f", date.timeIntervalSince1970);  
              
            //从现在起3600秒时候的时间  
            NSLog(@"%@", [NSDate dateWithTimeIntervalSinceNow:3600]);  
              
            //1970-01-01 00:00:00前3600秒的时间  
            NSLog(@"%@", [NSDate dateWithTimeIntervalSince1970:-3600]);  
              
            //返回一个很久之后的时间  
            NSLog(@"%@", [NSDate distantFuture]);  
              
            //返回一个很久之前的时间  
            NSLog(@"%@", [NSDate distantPast]);  
              
            //返回当前系统时区  
            NSLog(@"%@", [NSTimeZone systemTimeZone]);  
              
              
            //时间戳  格式化时间  
            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 年代标志符 
             y 年 
             M 月 
             d 日 
             h 时 在上午或下午 (1~12) 
             H 时 在一天中 (0~23) 
             m 分 
             s 秒 
             S 毫秒 
             E 星期 
             D 一年中的第几天 
             F 一月中第几个星期几 
             w 一年中第几个星期 
             W 一月中第几个星期 
             a 上午 / 下午 标记符  
             k 时 在一天中 (1~24) 
             K 时 在上午或下午 (0~11) 
             z 时区 
             */  
      
        }  
        return 0;  
    } 
    

    相关文章

      网友评论

          本文标题:时间格式化标签

          本文链接:https://www.haomeiwen.com/subject/dymddttx.html