Skip to content

Instantly share code, notes, and snippets.

@liulunet
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liulunet/51b6bcdebd29d84d6a83 to your computer and use it in GitHub Desktop.
Save liulunet/51b6bcdebd29d84d6a83 to your computer and use it in GitHub Desktop.
NSDateFormat
-(NSMutableDictionary*)dateDictionary
{
NSCalendar * chineseCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit |
NSSecondCalendarUnit | NSDayCalendarUnit |
NSMonthCalendarUnit | NSYearCalendarUnit;
NSDateComponents * cps = [chineseCalendar components:unitFlags fromDate:self];
NSUInteger hour = [cps hour];
NSUInteger minute = [cps minute];
NSUInteger second = [cps second];
NSUInteger day = [cps day];
NSUInteger month = [cps month];
NSUInteger year = [cps year];
NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
[dic setObject:[NSNumber numberWithInteger:hour] forKey:@"hour"];
[dic setObject:[NSNumber numberWithInteger:minute] forKey:@"minute"];
[dic setObject:[NSNumber numberWithInteger:second] forKey:@"second"];
[dic setObject:[NSNumber numberWithInteger:day] forKey:@"day"];
[dic setObject:[NSNumber numberWithInteger:month] forKey:@"month"];
[dic setObject:[NSNumber numberWithInteger:year] forKey:@"year"];
return dic;
}
- (NSString *)displayDateTime
{
NSString *format = @"";
NSDateFormatter *df=[[NSDateFormatter alloc] init];
NSTimeZone* localzone = [NSTimeZone localTimeZone];
NSTimeZone* GMTzone = [NSTimeZone timeZoneForSecondsFromGMT:0];
[df setTimeZone:localzone];
[df setDateFormat:@"yyyy-MM-dd HH:mm"];
format=[df stringFromDate:self];
return format;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment