The Unicode Date Format Template Guide ( here ) states that adding βaβ to the format will receive a period (for example, AM or PM), for example,
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss a"];
However, I want to make sure that the period information is not displayed, but I can not find the format string for this. The format string used is as follows:
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
Unfortunately, when I use stringFromDate, I get the following:
2013-01-09T11: 11:00 AM
I donβt want to just remove AM or PM from the result line, because the period syntax may differ on different calendars, etc., I just want to stop the period information from appearing.
---- 8 <------
Consider the following code
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setLocale:[NSLocale currentLocale]]; [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"]; NSString *stringDate = [formatter stringFromDate:[NSDate date]]; self.labelOutput.text = stringDate; [formatter release];
This code will create a string in the format I want, but I cannot use it to manage memory. The application I'm working on is suffering from NSDateFormatter memory leaks. Therefore, we use the singleton class to provide the installed NSDateFormatters number for an application that is never released, and therefore we minimize the number of memory leaks. Unfortunately, these static NSDateFormatters add AM / PM even when I apply the date format string, this way:
NSDateFormatter *formatter = [MyDateFormatter dateFormat:kFormatDateMediumStyleTimeShortStyle]; [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];