How to add characters to a NSString? - iphone

i have strings who look like this 20110525 .
how can i make to put '-' caracters in NSString variable ? to let dates look like this 2011-05-25 ?
My second question is how can i sort the dates to make the table look like this 20110525 then 20110526 ?Help please . Thank you

Why not just use the NSDate class to get the date, and use an NSDateFormatter to format the date the way you want.

you can try using sscanf(input,"%4d%2d%2s",&year,&month,&day) to parse input string and sprintf(output,"%d-%d-%d",year,month,day) to format your date.

Related

Matlab - isbusday and busdate format change

Would you be able to advise how can i change the format of the date the functions isbusday and busdate are using ?
The functions use US date format by default, but I need them to be in European format dd/mm/yyyy.
I have attempted to use the code below but it is not working.
isbusday('01-01-2015','dd-mm-yyyy')
busdate('01-01-2015','dd-mm-yyyy',1)
Thank you very much.
You want to convert your string to a datetime object. That is where you can control the format:
d = datetime('01-01-2015','InputFormat','dd-mm-yyyy');
isbusday(d)
busdate(t)
See the documentation: https://www.mathworks.com/help/matlab/ref/datetime.html and https://www.mathworks.com/help/finance/isbusday.html

converting a utc format date string to date object in Extjs

I have a date string in the format "2013-01-31T10:10:05.000Z". I want to convert this string to a Date object in extjs.
I have tried to use Ext.Date.parse("2013-01-31T10:10:05.000Z","Y-m-dTH:i:s.uZ"). But it is returning undefined.
I also tried with new Date("2013-01-31T10:10:05.000Z"), but it is also returning undefined.
Note: I have tried in IE8 browser.
Could anyone please help me to convert the above date string to Date object?
Thanks a lot sra. Now I am getting the result as ...UTC+5:30... Is there any way to convert this in IST format?
Try Ext.Date.parse("2013-01-31T10:10:05.000Z","c");
The c is the format type for ISO 8601 formatted dates
See the Ext.Date API for more details on this or other available formats
That's because 'T' and 'Z' are special characters in the Date format: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Date
You have to escape them like this: Ext.Date.parse("2013-01-31T10:10:05.000Z","Y-m-d\\TH:i:s.u\\Z")

Comparing the Key before adding to NSDictionary

I am adding dates into dictionary as the key and the corresponding value as some text ,but I am converting the date into string ,before adding to a dictionary,I have written the below code
[dateNoteDict setValue:datestring forKey:notes.text];
but before adding to dictionary I want to make some date comparision such that ,if the date present in dictionary is greater than ,the nest date then ,I should add below in the dictionary and so..on..
But I am not understanding how to do that.
So friends,please help me out..
Regards
Ranjit
You should do the comparison before converting the dates into NSStrings.
Assuming you are using NSDate objects, you can use the compare method. Have a look at this answer from S.O about date comparison.
Set some particular date format while setting as key in your dictionary. You can use NSDateFormatter for this. Also convert new date in the same format and then use "compare" for date comparison.
Thanks

Convert Formate of internet time to Nsdate Format in Desire

2011-08-06T12:29:10.703+05:30
i have following date that i have convert in this format like
"2011-08-06T12:29:10+05:30"
Here is a nice blog to have a better idea...
A more better explain is on this link
You can see that you need more than one date NSDateFormater for this job

xml parser, in iPhone

Am getting date (10/02/2011) in xmlresponse how to get this value in to string using NSXmlParserDelegate. "/" blocks me and am not getting how to handle this..
Thanks in advance..
Use NSDateFormatter to get date from NSString from any formats.
You have not been clear where this xml data is coming from, I couldnt turn anything up on how dates should be formatted in xml. The first thought is "you are doing it wrong" if you can try using a different separator for dates, parse them out of the stream before you give the data to NSXMLParser. I know which I would prefer.