• NSDate 时区转换问题


    一:

      NSDateFormatter *dateFormater = [[NSDateFormatter alloc]init];    
        [dateFormater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSTimeZone* localzone = [NSTimeZone localTimeZone];
        NSTimeZone* GTMzone = [NSTimeZone timeZoneForSecondsFromGMT:0];
        [dateFormater setTimeZone:GTMzone];
        [dateFormater setTimeZone:localzone];
        
        NSString *aStrDate = [[NSString alloc]initWithString:[dateFormater stringFromDate:[NSDate date]]];
        NSString *sendText = [NSString stringWithFormat:@"app测试发送:%@", aStrDate];
        NSLog(@"the send --> %@",sendText);

    二:

    1. NSTimeZone* localzone = [NSTimeZone localTimeZone];  
    2. NSTimeZone* GTMzone = [NSTimeZone timeZoneForSecondsFromGMT:0];  
    3. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];  
    4. [dateFormatter setDateFormat:GLOBAL_TIMEFORMAT];  
    5. [dateFormatter setTimeZone:GTMzone];  
    6. NSDate *bdate = [dateFormatter dateFromString:GLOBAL_TIMEBASE];  
    7. NSDate *day = [NSDate dateWithTimeInterval:(3600 + [localzone secondsFromGMT]) sinceDate:bdate];  
    8. NSString *text = [dateFormatter stringFromDate:day];  
  • 相关阅读:
    关于 js 下载PDF文件时
    vue3.0 学习
    iOS
    bootstrap treeview
    SVN版本管理
    js框架
    正则表达式
    如何让安卓手机在电脑上同步显示(MX4 Pro为例)
    mysql 中文乱码
    ADO.NET 数据库连接池大小
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3261876.html
Copyright © 2020-2023  润新知