随笔-OC获取系统时间,获取绝对时间,获得真实时间
- //获得系统时间
- NSDate * senddate=[NSDate date];
- NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
- [dateformatter setDateFormat:@"HH:mm"];
- NSString * locationString=[dateformatter stringFromDate:senddate];
- //[dateformatter setDateFormat:@"YYYY-MM-dd-HH-mm-ss"];
- //NSString * morelocationString=[dateformatter stringFromDate:senddate];
- //获得系统日期
- NSCalendar * cal=[NSCalendar currentCalendar];
- NSUInteger unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
- NSDateComponents * conponent= [cal components:unitFlags fromDate:senddate];
- NSInteger year=[conponent year];
- NSInteger month=[conponent month];
- NSInteger day=[conponent day];
- NSString * nsDateString= [NSString stringWithFormat:@"M年-月-日",year,month,day];
- [dateformatter release];
- string strYear="1988";
- string strMonth="09";
- string strDay="18";
- string strHour="5";
- string strMinutes="18";
- string strSec="20";
- morelocationString=[NSString stringWithFormat:@"%s-%s-%s-%s-%s-%s",strYear.c_str(),strMonth.c_str(),
- strDay.c_str(),strHour.c_str(),strMinutes.c_str(),strSec.c_str()];
- //根据时间字符串获得NSDate
- NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
- [dateformatter setDateFormat:@"YYYY-MM-dd-HH-mm-ss"];
- NSDate * oldDate=[dateformatter dateFromString:morelocationString];
- NSDate * oldDate=[dateformatter dateFromString:morelocationString];
- NSTimeInterval timeZoneOffset=[[NSTimeZone systemTimeZone] secondsFromGMT];
- NSDate * newDate=[oldDate dateByAddingTimeInterval:timeZoneOffset];
随笔-OC获取系统时间,获取绝对时间,获得真实时间相关推荐
- 获取系统时间戳 如文件备份带上时间
shell获取当天日期 date "+%Y%m%d" 前天时间 date -d "-1 day" 明天时间 date -d "day" 如对 ...
- android获取系统当前年月日时分秒的时间
2019独角兽企业重金招聘Python工程师标准>>> package itokit.com; import android.app.Activity; import android ...
- mysql怎么获取系统_MySQL获取系统性能和状态代码
代码如下: #!/bin/ksh INTERVAL=5 PREFIX=$INTERVAL-sec-status touch /tmp/running RUNFILE=/tmp/running my - ...
- VC++ 获取系统时间的方法汇总
1.使用CTime类(获取系统当前时间,精确到秒) ? 1 2 3 4 5 6 CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();/ ...
- 【VS开发】VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...
- linux 获取启动时间不对,linux获取系统启动时间
1.前言 时间对操作系统来说非常重要,从内核级到应用层,时间的表达方式及精度各部相同.linux内核里面用一个名为jiffes的常量来计算时间戳.应用层有time.getdaytime等函数.今天需要 ...
- Java 程序读取Mysql数据库时间信息与真实时间相差 13、14 小时、SQLException: HOUR_OF_DAY: 2 -> 3
CST时区引起的异常: Java 程序读取Mysql数据库时间信息,与真实时间相差 13.14 小时 java.sql.SQLException: HOUR_OF_DAY: 2 -> 3 原因: ...
- clock_gettime获取系统时间
clock_gettime获取系统时间 clock_gettime()是基于Linux C语言的时间函数,他可以用于计算精度和纳秒. 需要包含头文件 #include<time.h> 函数 ...
- linux系统gettime获取的时间,clock_gettime获取系统时间
clock_gettime获取系统时间 clock_gettime()是基于Linux C语言的时间函数,他可以用于计算精度和纳秒. 需要包含头文件 #include函数原型为 int clock_g ...
- Java获取系统日期时间
方法一:利用Calendar类来获取当前日期和时间,代码如下: /*** 获取系统时间* @return */public String getDate(){Calendar calendar = C ...
最新文章
- Iterator接口和for...of循环
- Git record
- windows环境下bat和python调用rysnc的方式
- (转)几种流行的JS框架的选择
- go gorm 密码隐藏_掀开华为云的Go语言编程底座!有深度、有点难、需细品(上)...
- Struts2技术详解
- JavaScript中正则表达式学习笔记
- HTML基础(part7)--常用标签之超链接标签
- Linux创始人Linus Torvalds怒怼Intel:正视问题而不是搞公关才是正事
- C++:编译实验之LR分析器
- Openlayer 3 的画图测量面积
- 面试准备每日五题:C++(十)——mapset、set查找、迭代器实现、set低层原理
- Prototype使用$H()函数
- c语言课程设计酒店管理系统实验报告 免费下载,C语言酒店管理系统设计
- java 按符号分割字符串_JAVA字符串按分隔符号字符串分割
- 什么是学习能力?如何提高学习能力?
- struct files_struct和struct fdtable
- 战火与秩序迁城显示服务器忙,战火与秩序迁城方法介绍
- android 聊天气泡背景图片,聊天气泡背景图片拉伸设置
- 反线性插值法进一步优化二分法解区间-M语言