这里的情况就是这样。我有现在的时代。而且我还有几天。我想找出两者之间的区别,给一些过去的时间,以划时代的形式。即
currentEpochTime - (x天)以划时代的格式给出一些过去的时间。
这就是我目前所得到的-
+ (double)currTimeInEpoch
{
NSDate *todayDate = [NSDate date];
double ti = [todayDate timeIntervalSince1970]*1000;
return ti;
}
+ (NSString *)timeDiff:(double)epoch diff:(double)diffInDays
{
double past = epoch - (diffInDays * 24 * 60 * 60 * 1000);
return [[NSNumber numberWithDouble:past] stringValue];
}
我做的对吗?不太确定。有更简单的方法吗?
发布于 2011-12-06 18:48:01
一个人去是危险的。拿着这个。
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.day = -40; // Number of days to subtract
NSDate *newDate = [[NSCalendar autoupdatingCurrentCalendar] dateByAddingComponents:dateComponents toDate:[NSDate date] options:0];
NSTimeInterval newDateInEpochTime = [newDate timeIntervalSince1970] * 1000;
https://stackoverflow.com/questions/8404740
复制相似问题