在目标c中:
NSDate *past = [NSDate date];
NSTimeInterval oldTime = [past timeIntervalSince1970];
NSString *timestamp = [[NSString alloc] initWithFormat:@"%0.0f", oldTime];在Javascript中:
new Date().getTime();问题是,在目标c中,时间戳由10个数字组成,而在javascript中则有13个数字。当我比较两者的差异是在15分钟内,我总是错误的。
有什么办法在目标c中得到13位数字的时间戳吗?
发布于 2014-03-26 21:47:25
getTime() gettime.asp
Returns the number of milliseconds since 1970/01/01:- (NSTimeInterval)timeIntervalSince1970
Returns the interval between the receiver and the first instant of 1 January 1970, GMT.
NSTimeInterval used to specify a time interval, in seconds.因此,需要将值乘以1000,才能将秒转换为毫秒。
NSDate *past = [NSDate date];
NSTimeInterval oldTime = [past timeIntervalSince1970];
NSString *timestamp = [[NSString alloc] initWithFormat:@"%0.0f", oldTime * 1000];https://stackoverflow.com/questions/22673645
复制相似问题