This is because -[NSDate description]
returns you full formatted date.
You can swizzle NSDate's - (NSString *)description{}
and return something that you want.
Note that this is a very bad practice
#import <objc/runtime.h>
@implementation NSDate (CustomDescription)
+ (void)load
{
swizzleInstance(@selector(description),
@selector(description_m),
[UIViewController class],
[self class]);
}
static void swizzleInstance(SEL originalSl, SEL swizzledSl, Class originalCl, Class swizzledCl) {
Method originalMethod = class_getInstanceMethod(originalCl, originalSl);
Method swizzledMethod = class_getInstanceMethod(swizzledCl, swizzledSl);
method_exchangeImplementations(originalMethod, swizzledMethod);
}
- (NSString *)description_m
{
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"dd-MM-yyyy"];
return [df stringFromDate:self];
}
@end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…