zoukankan      html  css  js  c++  java
  • ios 时间戳 当前时间 相互转化

    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.完成
  • 相关阅读:
    HDU
    HDU
    CodeForces
    HDU——2955 Robberies (0-1背包)
    南京区域赛之后
    算法作业三-哈夫曼编码
    HDU
    POJ 1220 NUMBER BASE CONVERSION(进制转换,大数)
    HDU 1535 Invitation Cards(最短路)
    HDU 3572 Task Schedule(网络流+当前弧优化)
  • 原文地址:https://www.cnblogs.com/Xer-Lee/p/3155151.html
Copyright © 2011-2022 走看看