我百度了好几种方法做时间戳,因为时间戳的单位是秒,所以给它*1000,但是它时间就不对了,我想知道正确的做时间戳的代码,希望大家帮帮忙

解决方案 »

  1.   

        NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
        NSTimeInterval a=[dat timeIntervalSince1970]*1000;  //  *1000 是精确到毫秒,不乘就是精确到秒
        NSString *timeString = [NSString stringWithFormat:@"%f", a]; //转为字符型   NSLog(@"%ld", time(NULL));  // 这句也可以获得时间戳,跟上面一样,精确到秒
    ======================
    网上搜的,有用没?
      

  2.   

    这种的试过不行啊,我还用过这种
    //时间转时间戳的方法:
            NSString *timeSjq = [NSString stringWithFormat:@"%d",(int)[dat timeIntervalSince1970]*-1000];
            NSString *timeSjx = [NSString stringWithFormat:@"%d",(int)[datenow timeIntervalSince1970]*-1000];
      

  3.   

    试试:double CurrentTime = CACurrentMediaTime();