Preprocessor Timestamp

前端 未结 3 928
时光说笑
时光说笑 2021-01-25 09:17

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

For instance: #define VERSION_EXPIRE __TIMESTAMP__

The reason for th

3条回答
  •  一个人的身影
    2021-01-25 09:25

    I've solved it as follows:

    #define VERSION_TIMESTAMP __DATE__" "__TIME__"\x0"
    

    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];
    }
    

提交回复
热议问题