代码之家  ›  专栏  ›  技术社区  ›  Era

预处理器时间戳

  •  1
  • Era  · 技术社区  · 14 年前

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

    例如: #define VERSION_EXPIRE __TIMESTAMP__

    原因是,我有beta版本,我想在编译时(在一个特殊的构建配置中)生成一个过期时间戳。

    3 回复  |  直到 10 年前
        1
  •  6
  •   schot    14 年前

    #define VERSION_TIMESTAMP __DATE__" "__TIME__"\x0"
    

    + (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];
    }
    
        2
  •  2
  •   Jens Gustedt    14 年前

    svn git $Id: $ $Date: $

    git archive --format=zip -9 -o project.zip HEAD file1 file2...
    

    .gitattributes

    file*   export-subst
    

    git-log

    #define P99_VERSION_DATE "$Format:%cd$"
    #define P99_VERSION_ID "$Format:%H$"
    

    #define P99_VERSION_DATE "Thu Oct 7 23:38:43 2010 +0200"
    #define P99_VERSION_ID "6f9740a6808ff50f42d24bb7b5234a904f84e6fe"
    
        3
  •  0
  •   AlcubierreDrive    14 年前