0

How to convert this type of Date Format to yyyy-MM-dd HH:MM:ss format.

                "DATE_OF_JOINING":"\/Date(1349634600000+0530)\/"
P.J
  • 6,547
  • 9
  • 44
  • 74
Arwin K
  • 52
  • 8

2 Answers2

0

use NSDateFormatter. This will let you format it many different ways, and into strings.

Here's apple's reference on the class for iOS: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html

apollosoftware.org
  • 12,161
  • 4
  • 48
  • 69
0

 I'd prefer a scanner over regular expressions to extract the time interval from the string

NSDictionary *dict = @{@"DATE_OF_JOINING" : @"Date(1357683534626+0530)"};

NSString *string = dict[@"DATE_OF_JOINING"];
NSString *intervalString;
NSString *offsetString;

NSScanner *scanner = [NSScanner scannerWithString:string];
[scanner setScanLocation:[string rangeOfString:@"("].location+1];
[scanner scanUpToCharactersFromSet:[NSCharacterSet characterSetWithCharactersInString:@"+-"] intoString:&intervalString];
[scanner scanUpToString:@")" intoString:&offsetString];

NSInteger hours = [[offsetString substringToIndex:3] integerValue];
NSInteger minutes = [[offsetString substringFromIndex:3] integerValue];
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
offsetComponents.hour = hours;
offsetComponents.minute = minutes;

NSTimeInterval interval= [intervalString doubleValue];

NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval/1000];

date = [[NSCalendar currentCalendar] dateByAddingComponents:offsetComponents toDate:date options:0];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *result = [formatter stringFromDate:date];
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
  • Hi, I need A help, If You are free, clarify me how to bind byte formatted image to png images. The link to my json Data is, http://hrmsiphone.atrity.info:7006/HRMSService.svc/GetEmployDetailsByEmpName/EmployeeNo=1. please do me the favour... – Arwin K Feb 11 '13 at 11:09
  • Seriously: that's a question u should ask in a new question — after searching stackoverflow. Most likely it is answered before. – vikingosegundo Feb 11 '13 at 14:29
  • Btw: please start to accept answers. Otherwise many users won't feel like they want to answer u. – vikingosegundo Feb 11 '13 at 14:30