Created
May 7, 2014 15:46
-
-
Save ishaq/1eef9f62757611b47ec4 to your computer and use it in GitHub Desktop.
category to remove fractional seconds from an NSDate
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
#import <Foundation/Foundation.h> | |
@interface NSDate (dateByRemovingFractionalSeconds) | |
+ (NSDate *)dateWithoutFractionalSeconds; | |
- (NSDate *)dateByRemovingFractionalSeconds; | |
@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
#import "NSDate+dateByRemovingFractionalSeconds.h" | |
@implementation NSDate (dateByRemovingFractionalSeconds) | |
+ (NSDate *)dateWithoutFractionalSeconds | |
{ | |
NSDate *now = [NSDate date]; | |
NSTimeInterval seconds = trunc([now timeIntervalSinceReferenceDate]); | |
NSDate *date = [[self class] dateWithTimeIntervalSinceReferenceDate:seconds]; | |
return date; | |
} | |
- (NSDate *)dateByRemovingFractionalSeconds | |
{ | |
NSTimeInterval seconds = trunc([self timeIntervalSinceReferenceDate]); | |
NSDate *date = [[self class] dateWithTimeIntervalSinceReferenceDate:seconds]; | |
return date; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment