0

i have tried formatting above date through @"YYYY-MM-dd'T'HH:mm:ss'+05:30'"

but getting wrong date(2012-04-18 23:59:59 +0000) can anyone help i have not found this type of format any where

Abhishek
  • 267
  • 2
  • 11
  • check https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html – parilogic Apr 01 '13 at 06:41

2 Answers2

0

The usual response is to use the strftime function/method, but since you are not specifying any platform or framework this is the best answer you can get; to search for a strftime function in your framework of choice.

pgf
  • 65
  • 1
  • 6
0

you are getting it correct value.but in the GMT format.That is what you give input is +5:30 in time and the value you have in return is in GMT format see the answer has +0000 at end shows it is GMT format.To check add the result with 5:30 you will have the right value that you provided. Use NSDateFormatter to get it the correct format of date

what you are missing here is a space between ss and 05:30 the correct format is

@"YYYY-MM-dd'T'HH:mm:ss '05:30'"

Use this to get the correct output

   NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd'T'HH:mm:ss '05:30'"];
    NSDate *dateObj= [dateFormatter dateFromString:@"2013-04-19T05:29:59 05:30"];
    NSLog(@"%@",dateObj);
    [dateFormatter setDateFormat:@"EEEE MMMM d, YYYY"];
    NSLog(@"%@",[dateFormatter stringFromDate:dateObj]);
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
  • thanks Lithu but can you check it for 2013-04-19T05:29:59+05:30 i have tried but din get right date – Abhishek Apr 01 '13 at 07:18
  • NSDate shows with the timezone, and you are 0530 hrs ahead of GMT, so you get time `2013-04-18 23:59:59 +0000` – Anoop Vaidya Apr 01 '13 at 08:49
  • @Abhishek : yeah you can check it but make sure the format and the entered time look alike in representation for this format.Note space also count – Lithu T.V Apr 01 '13 at 08:58
  • @Abhishek: For this format in comment use @"YYYY-MM-dd'T'HH:mm:ss'+05:30'" – Lithu T.V Apr 01 '13 at 09:00