-3

I am getting a NSString as @"27-Jan-2018 00:00".i just want to convert this string to NSDate class.Kindly suggest some methods to achieve this.Thanks in advance!

Prez
  • 227
  • 3
  • 12

2 Answers2

0

Try this...

NSString *dateString = @"27-Jan-2018 00:00";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];
[dateFormatter setDateFormat:@"dd-MMM-yyyy HH:mm"];
NSDate *dateFromString = [dateFormatter dateFromString:dateString];
NSLog(@"%@",dateFromString);
Nirav Kotecha
  • 2,493
  • 1
  • 12
  • 26
-3

Please, check it below code. Maybe its work for you and your needs.

 -(void)DateChange

 {

  NSString *Input_Date =@"31-Jan-18 04:25 AM";

  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
 [dateFormatter setDateFormat:@"dd-MMM-yy hh:mm a"];

  NSDate * Format_date = [dateFormatter dateFromString:Input_Date];
 [dateFormatter setDateFormat:@"dd-MMM-yy hh:mm a"];
  NSString *Change_date = [dateFormatter stringFromDate:Format_date];
  NSLog(@"Final Change Date :-  %@",Change_date);

 }



My Output is :- 
Final Change Date :- 31-Jan-18 04:25 AM