Reputation: 91
I have the text box with value 2016-01-12.I created the string like this
NSString * date = textbox.text;
Now the string having values 2016-01-12. I want to display like this.
"spent" : "2016-01-12"
Now i done
NSString * spent1 = @" \"spent\" : ";
NSString * new = [NSString stringWithFormat:@"%@%@",spent1,date];
Now i am getting like this:"spent":2016-01-12
But i need "spent":"2016-01-12"
.thanks for suggestion and help
Upvotes: 0
Views: 96
Reputation: 283
Try this...
NSString * date =@"2016-01-12";
NSString * dateStr=[NSString stringWithFormat:@"\"%@\"",date];
NSString * spent1 = @" \"spent\" : ";
NSString * new = [NSString stringWithFormat:@"%@ %@",spent1,dateStr];
NSLog(@"------>%@",new);
Upvotes: 0
Reputation: 5967
You can do this --
NSString * spent1 = [NSString stringWithFormat:@" \"spent\" : "/%@"/",date];
Or you can use Date formatter which is much more subtle as @Uma Madhavi suggested
Upvotes: 0
Reputation: 1832
NSString *str = [NSString stringWithFormat:@"\"%@\" : \"%@\"", @"spent", textbox.text];
Upvotes: 1
Reputation: 4917
For getting date means use this format.
NSDate *currDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"YYYY-MM-dd"];
NSString *dateString = [dateFormatter stringFromDate:currDate];
NSLog(@"date is %@",dateString);
Upvotes: 1