zoukankan      html  css  js  c++  java
  • ios代码实现时间设置NSDate

    本文转载至 http://www.baidu.com/link?url=dcQWiL1FD_She6P4RM2IvEeJas0_gtG3LkRNTV5H87X0AyKCHvwYjBz2hdcB2JVpTyMRhl6Hno2FX_U3TEDgZq

     
     
            //1),创建一个对象,赋值为当前日期date 创建的NSDate对象,获得的永远是0时区的时间,china是东八区,需要加上8个小时
            NSDate *date = [NSDate date];
            NSTimeZone *zone = [NSTimeZone systemTimeZone];//修改时区
            NSInteger interval1 = [zone secondsFromGMTForDate: date];//修改时区
            NSDate *localDate1 = [date  dateByAddingTimeInterval: interval1];//修改时区
            NSLog(@"今天%@", localDate1);
            
            //2),创建一个明天此时的日期(时间间隔是以秒为单位的)dateWithTimeIntervalSinceNow:
            NSDate *tomorrow = [NSDate dateWithTimeIntervalSinceNow:24 * 60 * 60];
            NSInteger interval2 = [zone secondsFromGMTForDate: tomorrow];
            NSDate *localDate2 = [tomorrow  dateByAddingTimeInterval: interval2];
            NSLog(@"明天%@", localDate2);
            
            //3),创建一个昨天此时的日期
            NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow:-24 * 60 * 60];
            NSInteger interval3 = [zone secondsFromGMTForDate: yesterday];
            NSDate *localDate3 = [yesterday dateByAddingTimeInterval: interval3];
            NSLog(@"昨天%@", localDate3);
  • 相关阅读:
    如何在centos上安装epel源
    Linux基础命令之cat使用方法大全
    Python正则表达式一: 基本使用方法
    Python 2.7 学习笔记 中文处理
    python 中 json的处理
    centos下网络代理服务器的配置
    centos7 在 vmware下的安装与配置
    Linux学习:find、chmod、ps命令
    Linux学习:netstat命令
    Linux学习:curl 与 wget命令
  • 原文地址:https://www.cnblogs.com/Camier-myNiuer/p/4236444.html
Copyright © 2011-2022 走看看