Created
March 9, 2011 07:08
-
-
Save hanksudo/861809 to your computer and use it in GitHub Desktop.
NSDate, NSString conversion and get TimeZone
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
// Get TimeZone | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"Z"]; | |
NSString *tz = [dateFormatter stringFromDate:[NSDate date]]; | |
[dateFormatter release]; | |
// Convert NSDate to NSString | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | |
NSString *strDate = [dateFormatter stringFromDate:[NSDate date]]; | |
[dateFormatter release]; | |
// Convert NSString to NSDate | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | |
NSDate *date = [dateFormatter dateFromString:@"2011-03-09 15:06:33"]; | |
[dateFormatter release]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment