Skip to content

Instantly share code, notes, and snippets.

@zhongge
Created December 14, 2014 11:48
Show Gist options
  • Save zhongge/612290f89dd43af10034 to your computer and use it in GitHub Desktop.
Save zhongge/612290f89dd43af10034 to your computer and use it in GitHub Desktop.
Q6. Get launched time of Application.
Any time is printed in Console. It isn't application start time.
+ initialize method may not invoked or lazily invoked.
So if you need the launched time of application, you must write the code in main function.
- AppDelegate.m
NSString * startTime;
- main.m
extern NString *startTime;
int main(int argc, char* argv[]) {
@autoreleasepool {
NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateStyle = NSDateFormatterNoStyle;
formatter.timeStyle = NSDateFormatterMediumStyle;
startTime = [formatter stringFromDate:[NSDate date]];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment