zoukankan      html  css  js  c++  java
  • OC时间格式化

    //
    //  main.m
    //  时间格式化
    ////
    
    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * 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;
    }
  • 相关阅读:
    UVA 10056 What is the Probability ?
    Reporting Services Report 带参数
    頁面刷新後,滾動條位置保持不變
    use this as the default and do not ask again
    JQuery Tab 滑动们导航菜单效果
    poj3256
    poj2060
    poj3280
    poj3261
    poj2135
  • 原文地址:https://www.cnblogs.com/yinshenge/p/4398813.html
Copyright © 2011-2022 走看看