I'm using the folowing code to get the date as a string
strStartDate.text=[mOnTimeApp->cDate descriptionWithLocale:nil];
It works but has the hour, minute and second. Is there a way to just get the Month, day and year as a string?
I'm using the folowing code to get the date as a string
strStartDate.text=[mOnTimeApp->cDate descriptionWithLocale:nil];
It works but has the hour, minute and second. Is there a way to just get the Month, day and year as a string?
Passing nil into descriptionWithLocale: is the same as calling description on an instance of NSDate. NSDate Class Reference has the following to say about descriptionWithLocale:
Return Value
A string representation of the receiver, using the given locale, or if the locale argument is nil, in the international format YYYY-MM-DD HH:MM:SS ±HHMM, where ±HHMM represents the time zone offset in hours and minutes from GMT (for example, “2001-03-24 10:45:32 +0600”)
You can configure an instance of NSDateFormatter to represent the desired format and then use the method stringFromDate: passing in your NSDate object -
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy"];
strStartDate.text = [formatter stringFromDate:mOnTimeApp->cDate];
Is this why you are looking for?
+ (NSString*)getAbsoluteDateAndTimeFromString:(NSNumber*)formattedTime
{
long long ts = [formattedTime longLongValue];
ts /= 1000;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:ts];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"M/d/yyyy h:mm a"];
return[dateFormatter stringFromDate:date];
}