#pragma mark - 获取当前时间戳
-(NSString *)getTimeSp{
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:];
//返回13位时间戳------12位的去掉 *1000
NSTimeInterval a=[dat timeIntervalSince1970]*;
NSString *timeString = [NSString stringWithFormat:@"%f", a];//转为字符型
return timeString;
} #pragma mark - 获取当前 yyyy-MM-dd HH:mm:ss 格式的时间
-(NSString *)getTime{
NSDate *fromdate=[NSDate date];
NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString* string=[dateFormat stringFromDate:fromdate];
return string;
} #pragma mark - 将yyyy-MM-dd HH:mm:ss 格式的时间转换成时间戳
/**
* timeStr : yyyy-MM-dd HH:mm:ss 格式的时间
*/
-(long)changeTimeToTimeSp:(NSString *)timeStr{
long time;
NSDateFormatter *format=[[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *fromdate=[format dateFromString:timeStr];
time= (long)[fromdate timeIntervalSince1970];
return time;
} #pragma mark - 将时间戳转为 yyyy-MM-dd HH:mm:ss 格式的时间
/**
* timeStr : 10/13位数时间戳
*/
-(NSString *)changeTimeSpToTime:(NSString *)timeStr{
unsigned long long createTime ;
/**
* 注意: 如果 timeStr 不是NSString类型,则需要将其转化为 NSString 类型,否则if判断会出错
* 转化代码 :NSString *t =[NSString stringWithFormat:@"%@",timeStr];
*/
if(timeStr.length == ){
// 10位时间戳
createTime = [timeStr longLongValue];
}else{
// 13位时间戳
createTime = [timeStr longLongValue] / 1000.0;
} NSDate *creatDate = [[NSDate alloc] initWithTimeIntervalSince1970:createTime]; NSDateFormatter *creatDateFormatter = [[NSDateFormatter alloc] init];
creatDateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString *orderTimeEnd = [creatDateFormatter stringFromDate:creatDate]; return orderTimeEnd;
}

iOS 时间转换的更多相关文章

  1. 安卓、ios时间转换成时间戳的形式

    将日期转换成时间戳的形式,在安卓和ios不同的系统下转正会有兼容性的问题 安卓系统下Date.parse(new Date('2018-03-30 12:00:00'))会直接转换成时间戳的形式(简单 ...

  2. [BUG]微信小程序ios时间转换

    描述 小程序ios   new Date('2019-08-14T08:00:00.000+0000')   显示为  <Date: null>. '2019-08-14T08:00:00 ...

  3. 移动端web开发安卓和ios客户端在时间转换上的差异性问题

    作为一名移动前端开发的人员,平时遇到的兼容性问题不在少数.那么,今天就来说一下最近遇到的一个小坑(关于Android和ios在时间转换上的差异性问题)话不多说,直接上重点. 最近接到了一个需求,很简单 ...

  4. iOS时间问题

    在iOS开发中,经常会遇到各种各样的时间问题,8小时时差,时间戳,求时间间隔,农历等等.解决办法网上比比皆是,但大多零零散散,很多资料并没有说明其中问题.这里集中总结一下,以便于以后查阅和供大家参考. ...

  5. iOS Json转换模型库:YYModel

    iOS Json转换模型库:YYModel   其实在研究这个库之前,市面上已经有很多类似的模型序列化成JSON及反序列化库(如Mantle.MJExtension)了,推荐他只是因为他高端的性能和容 ...

  6. [jquery]将当前时间转换成yyyymmdd格式

    如题: function nowtime(){//将当前时间转换成yyyymmdd格式 var mydate = new Date(); var str = "" + mydate ...

  7. MySQL 日期、时间转换函数

    MySQL 日期.时间转换函数:date_format(date,format), time_format(time,format) 能够把一个日期/时间转换成各种各样的字符串格式.它是 str_to ...

  8. java时间类型的转换/获取当前时间/将时间转换成String/将String转换成时间

    对于我的脑子,我已经服气了...写了N遍的东西,就是记不住...既然记不住那就记下来... 利用java获取当前的时间(String类型,年-月-日 时:分:秒) //我要获取当前的日期 Date d ...

  9. inner join ,left join ,right join 以及java时间转换

    1.inner join ,left join 与 right join (from 百度知道) 例表aaid adate1    a12    a23    a3表bbid  bdate1     ...

随机推荐

  1. Python中的namespace package

    在Python 3.3之前,一个目录想被当成package被导入,必须包含__init__.py文件:而在Python 3.3及以后的版本中,__init__.py文件可以不需要,直接使用import ...

  2. Coprime Sequence(前后缀GCD)

    Description Do you know what is called ``Coprime Sequence''? That is a sequence consists of $n$ posi ...

  3. keydown事件下调用trigger事件执行两次

    $('button[type=button]').on('click',login); //登录 $(document).keydown(function(event){ if(event.keyCo ...

  4. 如何将PDF的背景色设置为保护眼睛的苹果绿色

      福昕阅读器请戳这里.   Adobe Acrobat请戳这里.

  5. 软工实践原型设计——PaperRepositories

    软工实践原型设计--PaperRepositories 写在前面 本次作业链接 队友(031602237吴杰婷)博客链接 pdf文件地址 原型设计地址(加载有点慢...) 结对成员:031602237 ...

  6. Tiny4412 LED 程序

    package cn.hyc.led; import android.os.Bundle; import android.app.Activity; import android.view.Menu; ...

  7. Python爬虫requests判断请求超时并重新发送请求

     下面是简单的一个重复请求过程,更高级更简单的请移步本博客: https://www.cnblogs.com/fanjp666888/p/9796943.html  在爬虫的执行当中,总会遇到请求连接 ...

  8. Sitemesh小记

    一.前言 因参与公司框架改造,接触到了Sitemesh这个用于网页布局和修饰的框架,因之前没有接触过(汗颜),但是发现其小巧好用,便以此文记之~ 二.正文 Sitemesh有什么作用呢?我相信很多人在 ...

  9. 【python】python字符串前面加u,r,b的含义

    1.字符串前加 u 例:u"我是含有中文字符组成的字符串." 作用:后面字符串以 Unicode 格式 进行编码,一般用在中文字符串前面,防止因为源码储存格式问题,导致再次使用时出 ...

  10. 【题解】Atcoder ARC#90 E-Avoiding Collision

    自己做出来固然开心,但是越发感觉到自己写题的确是很慢很慢了……往往有很多的细节反反复复的考虑才能确定,还要加油呀~ 这道题目的突破口在于正难则反.直接求有多少不相交的不好求,我们转而求出所有相交的.我 ...