1. //获得系统时间
  2. NSDate * senddate=[NSDate date];
  3. NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
  4. [dateformatter setDateFormat:@"HH:mm"];
  5. NSString * locationString=[dateformatter stringFromDate:senddate];
  6. //[dateformatter setDateFormat:@"YYYY-MM-dd-HH-mm-ss"];
  7. //NSString * morelocationString=[dateformatter stringFromDate:senddate];
  8. //获得系统日期
  9. NSCalendar * cal=[NSCalendar currentCalendar];
  10. NSUInteger unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
  11. NSDateComponents * conponent= [cal components:unitFlags fromDate:senddate];
  12. NSInteger year=[conponent year];
  13. NSInteger month=[conponent month];
  14. NSInteger day=[conponent day];
  15. NSString * nsDateString= [NSString stringWithFormat:@"M年-月-日",year,month,day];
  16. [dateformatter release];
2. 从字符串来获得NSDate
  1. string strYear="1988";
  2. string strMonth="09";
  3. string strDay="18";
  4. string strHour="5";
  5. string strMinutes="18";
  6. string strSec="20";
  7. morelocationString=[NSString stringWithFormat:@"%s-%s-%s-%s-%s-%s",strYear.c_str(),strMonth.c_str(),
  8. strDay.c_str(),strHour.c_str(),strMinutes.c_str(),strSec.c_str()];
  9. //根据时间字符串获得NSDate
  10. NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
  11. [dateformatter setDateFormat:@"YYYY-MM-dd-HH-mm-ss"];
  12. NSDate * oldDate=[dateformatter dateFromString:morelocationString];
3. 从GMT时间,得到本地时间
  1. NSDate * oldDate=[dateformatter dateFromString:morelocationString];
  2. NSTimeInterval timeZoneOffset=[[NSTimeZone systemTimeZone] secondsFromGMT];
  3. NSDate * newDate=[oldDate dateByAddingTimeInterval:timeZoneOffset];

随笔-OC获取系统时间,获取绝对时间,获得真实时间相关推荐

  1. 获取系统时间戳 如文件备份带上时间

    shell获取当天日期 date "+%Y%m%d" 前天时间 date -d "-1 day" 明天时间 date -d "day" 如对 ...

  2. android获取系统当前年月日时分秒的时间

    2019独角兽企业重金招聘Python工程师标准>>> package itokit.com; import android.app.Activity; import android ...

  3. mysql怎么获取系统_MySQL获取系统性能和状态代码

    代码如下: #!/bin/ksh INTERVAL=5 PREFIX=$INTERVAL-sec-status touch /tmp/running RUNFILE=/tmp/running my - ...

  4. VC++ 获取系统时间的方法汇总

    1.使用CTime类(获取系统当前时间,精确到秒) ? 1 2 3 4 5 6 CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();/ ...

  5. 【VS开发】VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法

    1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...

  6. linux 获取启动时间不对,linux获取系统启动时间

    1.前言 时间对操作系统来说非常重要,从内核级到应用层,时间的表达方式及精度各部相同.linux内核里面用一个名为jiffes的常量来计算时间戳.应用层有time.getdaytime等函数.今天需要 ...

  7. Java 程序读取Mysql数据库时间信息与真实时间相差 13、14 小时、SQLException: HOUR_OF_DAY: 2 -> 3

    CST时区引起的异常: Java 程序读取Mysql数据库时间信息,与真实时间相差 13.14 小时 java.sql.SQLException: HOUR_OF_DAY: 2 -> 3 原因: ...

  8. clock_gettime获取系统时间

    clock_gettime获取系统时间 clock_gettime()是基于Linux C语言的时间函数,他可以用于计算精度和纳秒. 需要包含头文件 #include<time.h> 函数 ...

  9. linux系统gettime获取的时间,clock_gettime获取系统时间

    clock_gettime获取系统时间 clock_gettime()是基于Linux C语言的时间函数,他可以用于计算精度和纳秒. 需要包含头文件 #include函数原型为 int clock_g ...

  10. Java获取系统日期时间

    方法一:利用Calendar类来获取当前日期和时间,代码如下: /*** 获取系统时间* @return */public String getDate(){Calendar calendar = C ...

最新文章

  1. Iterator接口和for...of循环
  2. Git record
  3. windows环境下bat和python调用rysnc的方式
  4. (转)几种流行的JS框架的选择
  5. go gorm 密码隐藏_掀开华为云的Go语言编程底座!有深度、有点难、需细品(上)...
  6. Struts2技术详解
  7. JavaScript中正则表达式学习笔记
  8. HTML基础(part7)--常用标签之超链接标签
  9. Linux创始人Linus Torvalds怒怼Intel:正视问题而不是搞公关才是正事
  10. C++:编译实验之LR分析器
  11. Openlayer 3 的画图测量面积
  12. 面试准备每日五题:C++(十)——mapset、set查找、迭代器实现、set低层原理
  13. Prototype使用$H()函数
  14. c语言课程设计酒店管理系统实验报告 免费下载,C语言酒店管理系统设计
  15. java 按符号分割字符串_JAVA字符串按分隔符号字符串分割
  16. 什么是学习能力?如何提高学习能力?
  17. struct files_struct和struct fdtable
  18. 战火与秩序迁城显示服务器忙,战火与秩序迁城方法介绍
  19. android 聊天气泡背景图片,聊天气泡背景图片拉伸设置
  20. 反线性插值法进一步优化二分法解区间-M语言

热门文章

  1. 最优化方法-抛物线法原理及MATLAB实现
  2. 异常处理基于注解ExceptionHandler
  3. Android线程优化
  4. protect 继承_c++三种继承方式public,protect,private
  5. 不会这 9 种常用的软件工具!你敢说你会网络安全?
  6. python 异常处理 库_python捕获数据库异常处理
  7. 信息学奥赛一本通-1047
  8. clob类型字段最大存储长度_Oracle的CLOB大数据字段类型
  9. 下载网页视频并自动合成视频
  10. npm使用国内淘宝镜像的方法(两种)