How to get date in “yyyy-MM-dd'T'HH:mm:ss.SSSZ” format?


i have date in this format 2014-09-20 04:45:20 +0000 and i need to convert this to yyyy-MM-dd'T'HH:mm:ss.SSSZ format.I tried with the following code

NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"]; NSDate *date = [formatter dateFromString:@"2014-09-20 04:45:20 +0000"]; NSLog(@"%@",date);

but date giving me null value..

I am geting 2014-09-20 04:45:20 +0000 from time picker so anythg needs to be done on picker side will also help me.


Try this:

NSString *aStrDate = @"2014-09-20 04:45:20 +0000"; NSDateFormatter *aDateFormatter = [[NSDateFormatter alloc] init]; aDateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss Z"; NSDate *aDate = [aDateFormatter dateFromString:aStrDate]; aDateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; NSLog(@"%@",[aDateFormatter stringFromDate:aDate]);


  • Convert string to date with timezone
  • Convert the format of date in javascript
  • In JAVA, how do you calculate time difference between two dates in string format where both the time
  • Annotation as shortcut for another annotation?
  • iOS - Proper formatting of timestamps between mySQL (apache) and iOS (NSDate)
  • iOS6 TimeInterval bug
  • converting a String to java.util.Date
  • UIView drawRect vs initWithFrame
  • How detect time settings of device?
  • How to convert a Persian date into a Gregorian date in xcode?
  • Jackon 2.4.2 failing to deserialize valid date, even after specifying date format
  • Objective C / iPhone: How do I extract the actual unicode date format strings for the current region
  • Sqlite query, compare datetime field with current date time
  • UIdatepicker showing weekdays
  • problem with calling libraries
  • boost::format vs sprintf
  • html5 tag support
  • SpriteKit SKScene add AVCaptureVideoPreviewLayer CALayer as background not working
  • Cleave.js Phone CA
  • IF statement formatting best-practise, what's your style?
  • How to parsing NSDate to RFC 822 always use in English?
  • date: illegal option — d, Find difference between two dates
  • iOS Date formatting
  • x-axis labels in coreplot not displayed
  • How to make the tableview response pan gesture in ZUUIRevealController
  • iOS - MKOverlayView custom view rect fills works, but line draws do not
  • UIScrollView setContentOffset: animated: not working
  • How do I add a UIAlertController in app delegate (obj-c)
  • GKLeaderboardViewController initial leaderboard
  • Add Labeltext on Mkannotation image
  • iOS 6 dateFromString returns wrong date
  • “A GKScore must specify a leaderboard.”
  • Question about instantiating object
  • NSScanner Loop Question
  • Pass value from viewmodel to script in zk
  • Microsoft Visual Studio Community 2015 always crashes in Windows 10 if swithed to Visual FoxPro
  • Eraser for UIBezierPath
  • Compare two NSDates in iPhone
  • trying to dynamically update Highchart column chart but series undefined
  • Load html files in TinyMce