0

In the API , the selected day format is like 2013-11-01T23:00:00%2B0000

But my date format is like this: 2013-11-01T23:00:00+0000

To convert, I have used below code:

NSString *plus = [NSString stringWithFormat:@"%@%@", [timeStamp substringToIndex:[timeStamp length]-5], @"%2B0000"];

Instead of (+) the unicode of plus which is (%2B).

But when I select the day from Tapku calender, I receive the error which says date format is wrong. How can I fix this problem?

Cœur
  • 37,241
  • 25
  • 195
  • 267
santa
  • 147
  • 1
  • 4
  • 16

3 Answers3

7
           NSDate *tempDate=toDate;

           NSDateFormatter *df = [[NSDateFormatter alloc] init];
           [df setDateFormat:@"yyyy-MM-dd HH:mm:ss zzzz"];



           [periodOfInspectionToTextField setText:[NSString stringWithFormat:@"%@",[df stringFromDate:d]]];
           toDate=[df dateFromString:periodOfInspectionToTextField.text];
Albin Joseph
  • 1,133
  • 15
  • 27
  • But in the api that im getting data the formate is utc . And when it is like this **2013-11-01T23:00:00+0000** I dont have problem. But the api formate doesnt accept (+)plus that I have. So i have to use the unicode of (+)plus. In this situation , Tapku doesnt accept. That is the problem. Am I clear? – santa Nov 06 '13 at 12:16
  • 1
    [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss z"] if you are set the formatter like this you will get answer like this " 2013-11-08T05:30:00 GMT+5:30" if you know more about date format you just refer these two links http://waracle.net/iphone-nsdateformatter-date-formatting-table/ and http://b2cloud.com.au/how-to-guides/nsdateformatter-format-strings – Albin Joseph Nov 06 '13 at 12:36
  • I have already gotten the date formate like this. But my problem is that I need to get like this: 2013-11-01T23:00:00%2B0000 for the formate of my api. But in this case tapku calender doesnt recognize this is a date. ? – santa Nov 06 '13 at 12:40
0

You need to set the dateformat of tapku which is below:-

   [YYYY-MM-DD hour:minute:second];

Also follow this link for more details.

Tapku library -what is the date format in day view

Community
  • 1
  • 1
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
0

First, you need to unescape the date string from the API to remove the percent escapes:

NSString *dateString = [@"2013-11-01T23:00:00%2B0000" stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

This will give a date string of 2013-11-01T23:00:00+0000. Then you need to parse this string into a NSDate object:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:sszzzz"];

NSDate *date = [formatter dateFromString:dateString];
neilco
  • 7,964
  • 2
  • 36
  • 41
  • In this situation date is nil – santa Nov 06 '13 at 12:48
  • @santa I've just run the code in Xcode and [here's the output I get](http://cl.ly/SKts). The `date` variable is not `nil`. – neilco Nov 06 '13 at 12:59
  • sorry , i made a mistake for this it was nil. But I have already had this result. the api formate doesnt accept this formate. In the api formate instead of ** (+ )** plus I need to show **( %2B )** this character . %2B is the unicode of +(plus). – santa Nov 06 '13 at 14:15