1.今天在做一个webservice的接口的时候,被要求传一个时间戳过去,然后就是开始在Google上找

2.遇到两个问题,一,当前时间转化为时间戳,二,获取的当前时间和系统的时间相差8个小时
一,转化的方法为
    NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[localeDate timeIntervalSince1970]];
    NSLog(@"timeSp:%@",timeSp); //时间戳的值
 
二,把获取的时间转化为当前时间
 NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate:datenow];
    NSDate *localeDate = [datenow  dateByAddingTimeInterval: interval];
    NSLog(@"%@", localeDate);
 
3.把时间戳转化为时间的方法
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1363948516];
    NSLog(@"1363948516  = %@",confromTimesp);
 
4.完成

ios 时间戳 当前时间 相互转化的更多相关文章

  1. iOS 时间戳和时间互换,计算两日期相隔天数

    /*  *获取当前系统时间的时间戳  */ +(NSInteger)getNowTimestamp;   /**  * 获取当前时间  */ + (NSString *)getNowTimeTampF ...

  2. iOS 时间戳转换为时间

    NSString *str=";//时间戳 NSTimeInterval time=[str doubleValue]+;//因为时差问题要加8小时 == 28800 sec NSDate ...

  3. C# 时间戳与时间相互转化

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 时间戳d ...

  4. iOS开发时间戳与时间NSDate,时区的转换,汉字与UTF8,16进制的转换

    http://blog.sina.com.cn/s/blog_68661bd80101njdo.html 标签: ios时间戳 ios开发时间戳 ios16进制转中文 ios开发utf8转中文 ios ...

  5. PHP 时间戳 转时间 for ios 8*3600

    // 时间戳 转时间 int intTimeString = [_model.date intValue]; NSDate *confromTimesp = [NSDate dateWithTimeI ...

  6. (转)golang获取当前时间、时间戳和时间字符串及它们之间的相互转换

    原文连接: https://blog.csdn.net/skh2015java/article/details/70051512 1.获取当前时间 currentTime:=time.Now() // ...

  7. Swift3.0 iOS获取当前时间 - 年月日时分秒星期

    Swift3.0 iOS获取当前时间 - 年月日时分秒星期func getTimes() -> [Int] { var timers: [Int] = [] // 返回的数组 let calen ...

  8. mysql取出现在的时间戳和时间时间戳转成人类看得懂的时间

    mysql取出现在的时间戳和时间时间戳转成人类看得懂的时间,我们在mysql里面他封装了一个内置的时间戳转化的函数,比如我们现在的时间戳是:1458536709 ,"%Y-%m-%d&quo ...

  9. IOS时间戳

    什么是时间戳? 时间戳(timestamp),通常是一个字符序列,唯一地标识某一刻的时间.数字时间戳技术是数字签名技术一种变种的应用. 思考:简单来讲就是根据文件hash加密后生成的摘要和时间生成的时 ...

随机推荐

  1. Notepad++打开xml文件显示crlf的问题

    如图所示,显示CRLF,  CRLF其实是换行符. 所以在下图所示设置下显示行尾符不显示即可.

  2. android studio怎么添加.so文件?android studio加载so文件的方法

    android studio 中 添加.so 文件,Android Studio中添加.jar文件和.so文件无疑是一件很重要也是很头疼的问题! 1.在src/main中添加 jniLibs文件夹 , ...

  3. CSDN code使用教程之git使用方法具体解释

          首先须要下载GITclient.http://git-scm.com/downloads. . . 然后再code.csdn.net上面创建一个项目,假设 你的项目已经存在.那么请建立项目 ...

  4. [TypeScript] Use the never type to avoid code with dead ends using TypeScript

    Example 1: A never stop while loop return a never type. function run(): never { while(true){ let foo ...

  5. 使用apidoc 生成Restful web Api文档

    在项目开发过程中,总会牵扯到接口文档的设计与编写,之前使用的都是office工具,写一个文档,总也是不够漂亮和直观.好在git上的开源大神提供了生成文档的工具,so来介绍一下! 该工具是Nodejs的 ...

  6. HDU 3215 The first place of 2^n (数论-水题)

    The first place of 2^n Problem Description LMY and YY are mathematics and number theory lovers. They ...

  7. 小强的HTML5移动开发之路(28)—— JavaScript回顾3

    一.基本数据类型 number:数字类型 string:字符串 (注意s小写:string是基本类型) boolean:布尔类型   //前三个都有对应的包装类 null:空类型 undefined: ...

  8. 选择性编译代码:如 #ifdef __IPHONE_7_0

    选择性编译代码: 选择性编译代码和选择性运行代码是不一样的,区别在于: 1.选择性编译代码是在硬件或者系统不支持的情况下不会对该段代码进行编译,也就不会由于不兼容的问题导致报错 #import < ...

  9. 【erlang 网络编程学习】 分析cowboy acceptor实现

    http://www.tuicool.com/articles/vuymei 不知道为什么就看了cowboy代码,就继续看了下去了. 分析一下吧,主要写写cowboy 的acceptor pool 的 ...

  10. html中DIV+CSS与TABLE布局方式的区别及HTML5新加入的结构标签(转)

    DIV与TABLE布局的区别 div 和 table 的加载方式不同,div 的加载方式是即读即加载,遇到 <div> 没有遇到 </div> 的时候一样加载 div 中的内容 ...