是否可以通过预处理器宏生成嵌入式 Unix 时间戳?
例如:#define VERSION_EXPIRE __TIMESTAMP__
这样做的原因是,我有测试版,我想在编译时生成一个过期时间戳(在特殊的构建配置中)。
最佳答案
我是这样解决的:
#define VERSION_TIMESTAMP __DATE__" "__TIME__"\x0"
在其他类(class)
+ (NSDate *)versionExpiresInDays:(NSUInteger)days {
NSString *dateString = [NSString stringWithUTF8String:VERSION_TIMESTAMP];
NSLocale *enLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
NSDate *compiledOn = [NSDate dateWithNaturalLanguageString:dateString locale:enLocale];
return [compiledOn dateByAddingTimeInterval:days*24*60*60];
}
关于objective-c - 预处理器时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3905644/