Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone/OS X: Convert UTC format date&time value Calendar required format
    text
    copied!<p>I am struggling a bit to convert the UTC time to the date format what i want.</p> <pre><code>2012-03-10T09:30:00Z </code></pre> <p>needs to be converted to the below format</p> <pre><code>3:00:00pm April 19, 2012 </code></pre> <p>Could you someone please help me to resolve this?</p> <p>I tried like below,</p> <pre><code> NSString *formatted; NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"HH:mm:ss EEEE, MMM d"]; // Here datetime= 2012-03-10T09:30:00Z NSDate *date = [NSDate dateWithTimeIntervalSince1970: [datetime intValue]]; NSString *dateString = [formatter stringFromDate:date]; NSLog(@"dateString: %@", dateString); </code></pre> <p>But, its printing wrong date like "06:03:32 Thursday, Jan 1". Please correct me.</p> <p><strong>UPDATED:</strong> I am having another problem, its not giving me the correct time, but its giving the correct date though. My Code is below. </p> <pre><code>NSString *formatted; NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"HH:mm:ss EEEE, MMM d"]; NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"]; NSDate *date = [df dateFromString:datetime]; NSString *dateString = [formatter stringFromDate:date]; NSLog(@"dateString: %@", dateString); </code></pre> <p>Thank you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload