来源:http://www.daytimesoftware.com/blog/2007/10/suicidal-code-redux
// Based on original code by Daniel Jakult, based on an idea from Brian Cooke. #ifdef BETA // 4 week expiration #define EXPIREAFTERDAYS 28 #endif #if EXPIREAFTERDAYS NSString* compileDateString = [NSString stringWithUTF8String:__DATE__]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@”en_US”] autorelease]]; [dateFormatter setDateFormat:@"MMM dd yyyy"]; NSDate *compileDate = [dateFormatter dateFromString:compileDateString]; [dateFormatter release]; NSDate *expireDate = [compileDate addTimeInterval:(60*60*24* EXPIREAFTERDAYS)]; if ([expireDate earlierDate:[NSDate date]] == expireDate) { // Run an alert or whatever // Quit! [NSApp terminate:self]; } #endif