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;

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM