I need a NSString with the format "yyyy-mm-dd - 11:00:00"
Year, month, and date should be from the current date, while hour, minute, and second should be 11,00,00. I could not figure how to do that.
I need a NSString with the format "yyyy-mm-dd - 11:00:00"
Year, month, and date should be from the current date, while hour, minute, and second should be 11,00,00. I could not figure how to do that.
I think you mean yyyy-MM-dd - HH:mm:ss
(because mm
is minutes and MM
is month). But you just need
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd - HH:mm:ss";
NSString *string = [formatter stringFromDate:[NSDate date]];
Or if you want it to say 11:00:00
, either pass it that NSDate
, or you could:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd' - 11:00:00'";
NSString *string = [formatter stringFromDate:[NSDate date]];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd";
NSString *string = [NSString stringWithFormat:@"%@ - 11:00:00", [formatter stringFromDate:[NSDate date]]];