Last active
October 6, 2020 17:43
-
-
Save MLKrisJohnson/779d0d5424f168ca8f6f6111c7b0c1a2 to your computer and use it in GitHub Desktop.
Objective-C: Return current date/time in "yyyy-MM-dd HH:mm:ss.SSS Z" format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns current date/time in "yyyy-MM-dd HH:mm:ss.SSSS Z" format using the | |
// system timezone. | |
// | |
// Note that this includes fractional seconds, unlike the system log, so it | |
// is useful when precise times are desired in log output. | |
static NSString* timestampString() | |
{ | |
// Re-use one NSDateFormatter instance for all calls. | |
// NSDateFormatter is thread-safe for iOS 7+. | |
static NSDateFormatter* df; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
df = [[NSDateFormatter alloc] init]; | |
df.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSSS z"; | |
}); | |
return [df stringFromDate:[NSDate date]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment