iOS开发之获取时间戳方法

// 得到当前本地时间,13位,整形

+ (long long)gs_getCurrentTimeToMilliSecond {

    double currentTime = [[NSDate date] timeIntervalSince1970] * 1000;

    long long iTime = (long long)currentTime;

    return iTime;

}

 

//得到当前时间相对1970时间的字符串,精度到秒,返回10位长度字符串

+ (NSString *)gs_getCurrentTimeBySecond {

    double currentTime =  [[NSDate date] timeIntervalSince1970];

    NSString *strTime = [NSString stringWithFormat:@"%.0f",currentTime];

    return strTime;

}

 

/** 得到当前时间相对1970时间的字符串,精度到毫秒,返回13位长度字符串*/

+ (NSString *)gs_getCurrentTimeStringToMilliSecond {

    double currentTime =  [[NSDate date] timeIntervalSince1970]*1000;

    NSString *strTime = [NSString stringWithFormat:@"%.0f",currentTime];

    return strTime;

}

posted @ 2019-04-22 21:05  kawerd  阅读(10579)  评论(0编辑  收藏  举报