You can't format an NSDate, it is an exact point in time. If you are converting an NSDate to a string, and back to a NSDate, they will be identical
Get formatted date as NSDate [duplicate]
-
16-06-2023 - |
Question
I've a NSDateFormatter set like this:
YYYY/MM/dd HH:mm:ss
I can convert it from NSDate
to NSString
and from NSString
to NSDate
.
But what I want is to get the NSDate as I formatted it.
I thought about converting it to NSString
then convert back to NSDate
but this way is just awful, I'm sure there is a simpler way, right?
Solution
OTHER TIPS
A date is never formatted. The string representation and only the string representation of a date is formatted.
May be you want to write simple category to NSDate that will return right formatted string?
NSDate+formatted.h
@interface NSDate (formatted)
-(NSString)formatedString;
@end
NSDate+formatted.m
@implementation NSDate (formatted)
-(NSString)formatedString
{
// your formatter code here
}
@end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow