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;

}

猜你喜欢

转载自www.cnblogs.com/hecanlin/p/10753002.html
今日推荐