预处理器时间戳 [英] Preprocessor Timestamp

查看:166
本文介绍了预处理器时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过预处理器宏生成嵌入式Unix时间戳?

Is it possible to generate an embedded Unix timestamp via a preprocessor macro?

例如: #define VERSION_EXPIRE __TIMESTAMP __

这样做的原因是,我有beta版本,我想在编译时生成一个expire时间戳(在特殊的生成配置)。

The reason for this is, that i have beta versions and i want to generate an expire timestamp on compile time (in a special build configuration).

推荐答案

我已解决它如下:

#define VERSION_TIMESTAMP __DATE__" "__TIME__"\x0"

/ p>

In some other 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];
}

这篇关于预处理器时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆