I am creating a date and time string that is used to timestamp a file saved to the documents directory. Everything is working, except the time keeps displaying as 08/42/43 instead of 08:24:43. I’m not sure where the backslashes are coming from.
Here is the file name I am getting “2012_09_24 _ 08/42/43.cmm.” I added the underscores because I didn’t want backslashes for the date. The only issue is that the time has the backslashes. Here is the actual code.
NSDate *myDate = [NSDate date];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy_MM_dd '_' hh:mm:s"];
NSString *dateForFilename = [df stringFromDate:myDate];
This happens because ‘:’ is not a valid character for a filename (at least for OSX and hence iOS), so the system fallbacks to ‘/’. If you try something like this it should work ok: