I basically need to get current date and time separately, formatted as:
2009-04-26 11:06:54
The code below, from another question on the same topic, generates
now: |2009-06-01 23:18:23 +0100| dateString: |Jun 01, 2009 23:18| parsed: |2009-06-01 23:18:00 +0100|
This is almost what I'm looking for, but I want to separate the day and time.
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"MMM dd, yyyy HH:mm"];
NSDate *now = [[NSDate alloc] init];
NSString *dateString = [format stringFromDate:now];
NSDateFormatter *inFormat = [[NSDateFormatter alloc] init];
[inFormat setDateFormat:@"MMM dd, yyyy"];
NSDate *parsed = [inFormat dateFromString:dateString];
NSLog(@"\n"
"now: |%@| \n"
"dateString: |%@| \n"
"parsed: |%@|", now, dateString, parsed);
Best Answer
this is what i used: