0

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.

lnafziger
  • 25,760
  • 8
  • 60
  • 101
yabtzey
  • 391
  • 1
  • 7
  • 17

2 Answers2

1

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]];
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • It seems he wants time to be 11:00:00 – Andrey Gordeev Sep 04 '13 at 04:14
  • Yes, But i need the time format to be custom. you code will give me curent date and time. but I need a string like 2013-809-04 - 11:00:00. The time 11.00.00 should always be the same but the date needs to be changed – yabtzey Sep 04 '13 at 04:15
0
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd";
NSString *string = [NSString stringWithFormat:@"%@ - 11:00:00", [formatter stringFromDate:[NSDate date]]];
Timur Bernikovich
  • 5,660
  • 4
  • 45
  • 58