Created
April 9, 2013 10:13
-
-
Save maxhuk/5344631 to your computer and use it in GitHub Desktop.
Fast date formatting.
This file contains 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
// | |
// NSString+DateFormatter.h | |
// | |
// Created by Maksym Huk on 3/31/13. | |
// Copyright (c) 2013 Maksym Huk. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#define DateFormatDate @"yyyy-MM-dd" | |
#define DateFormatTime @"HH:mm:ss" | |
@interface NSString (DateFormatter) | |
+ (NSString *)stringFromDate:(NSDate *)date dateFormat:(NSString *)dateFormat; | |
+ (NSString *)stringFromDate:(NSDate *)date dateFormat:(NSString *)dateFormat locale:(NSLocale *)locale; | |
@end |
This file contains 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
// | |
// NSString+DateFormatter.m | |
// | |
// Created by Maksym Huk on 3/31/13. | |
// Copyright (c) 2013 Maksym Huk. All rights reserved. | |
// | |
#import "NSString+DateFormatter.h" | |
@implementation NSString (DateFormatter) | |
+ (NSString *)stringFromDate:(NSDate *)date dateFormat:(NSString *)dateFormat | |
{ | |
return [self stringFromDate:date dateFormat:dateFormat locale:nil]; | |
} | |
+ (NSString *)stringFromDate:(NSDate *)date dateFormat:(NSString *)dateFormat locale:(NSLocale *)locale | |
{ | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
dateFormatter.locale = locale; | |
dateFormatter.dateFormat = dateFormat; | |
return [dateFormatter stringFromDate:date]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment