logo
down
shadow

return nil for dateFromString call of NSDateFormatter


return nil for dateFromString call of NSDateFormatter

By : Marcelo J. Garcia
Date : November 22 2020, 07:01 PM
may help you . I am getting nil returned for the date variable in the below code. I can't find any problem with the date format, can anyone help? , Try
code :


Share : facebook icon twitter icon
NSDateFormatter DateFromString return nil

NSDateFormatter DateFromString return nil


By : Johnny B.
Date : March 29 2020, 07:55 AM
Any of those help I Know it may be got answered a lot here but i think i have a different case , You should handle zone too. Correct variant:
code :
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
NSDateFormatter dateFromString return wrong year

NSDateFormatter dateFromString return wrong year


By : user3680102
Date : March 29 2020, 07:55 AM
To fix this issue The issue is the locale of the formatter. If you want to use gregorian calendar regardless of the device settings, you generally should set locale to en_US_POSIX.
code :
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
NSDateFormatter dateFromString with format 'hh:mm a' return nil

NSDateFormatter dateFromString with format 'hh:mm a' return nil


By : Vuash
Date : March 29 2020, 07:55 AM
I wish this helpful for you I'm assuming your device language is other then English. In that case you need to set the date formatter Locale. Try this code.
code :
NSString *time = @"01:30 PM";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"hh:mm a"];
[dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
NSDateFormatter dateFromString return null

NSDateFormatter dateFromString return null


By : Nikita Krivov
Date : March 29 2020, 07:55 AM
Hope this helps Your code is correct.
If the device is set to AM/PM time and requested string format is set to @"yyyy-MM-dd HH:mm:ss" dateFromString will return nil. Try setting the locale like :
code :
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
NSDateFormatter dateFromString produces nil after first call in same method

NSDateFormatter dateFromString produces nil after first call in same method


By : Ivaylo Kunev
Date : March 29 2020, 07:55 AM
I hope this helps you . In the second string, the hour is 17 (24-hour format) but the format string uses hh (lowercase) which is for 12-hour format.
Change the format string to yyyy-MM-dd HH:mm:ss Z.
Related Posts Related Posts :
  • NSString with \n or line break
  • When to retain a "delegate"
  • Why am I allowed to write and use methods in an implementation that aren't declared in the header file in Objective-C?
  • Reading Alias files
  • NSMutableArray accessing issue
  • NSString (hex) to bytes
  • How to order a window to front if you are not in the Application in Objective-C
  • What is the use of extern in declaring constants?
  • Why is Objective-C not very popular outside of the Apple community?
  • Can I assign array size using NSMutableArray?
  • incorrect variable value outside main()
  • How to concatenate two float values in Objective-C?
  • How to compare string with float? in Objective C
  • How to use Calibri font?
  • CoreData many-to-many relationship NSPredicate Exceptions
  • Objective-C Framework PSMTabBarControl does not work - NSTabView Tabs with Style
  • How to use Doxygen with Xcode?
  • Creating Custom Twitter Application
  • Fastest way to iterate through an NSArray with objects and keys
  • How can I compare two dates, return a number of days
  • Extract values between parenthesis from NSString
  • How do browsers know there is an RSS feed present for a given URL
  • How to add info button to UIToolbar
  • Cocoa: getting a Table View cell to send action messages
  • releasing arrays objective-c
  • UIScrollView with pages enabled and device rotation/orientation changes (MADNESS)
  • "incomplete universal character name" with stringWithUTF8String
  • What is the main difference between framework and dynamic library
  • How to make a blue button with white text?
  • Memory leak in NSMutableArray allocation
  • NSCFString leak inVolving NSString
  • NSCFArray leak in the NSMutablearray allocation
  • How to use NSURLDownload
  • How to enlarge dynamically an UILabel (label and font size)?
  • App crashes after a few seconds
  • Undocumented Mac Calls
  • How do I release an object allocated in a different AutoReleasePool?
  • How to edit Selection indicator in UIPicker?
  • AVPlayerViewController - How to display always playback controls
  • How can I make the Tab key move focus out of a NSTextView?
  • How do I add Applescript support to my Cocoa application?
  • Is there a Javadoc-like plugin for Xcode that automatically generates the doc template?
  • UIKeyBoard resize on orientation change to landscape
  • wait for CLLocationManager to finish before tweeting
  • Difference between char *foo vs (char *)foo in Objective-C
  • Objective C / iPhone: How to add a timer to let the text update?
  • how to keep the UIActivityIndicator "floating" above the UITable?
  • How to remove subviews to release more memory
  • Deallocating NSMutableArray of custom objects
  • Get TopLeft and BottomRight from MKCoordinateRegion MKMapView
  • How to use Obj-C classes in MacRuby
  • cocoa hello world screensaver
  • how do i know when to use a datasource or delegate protocol when using a UI object in my project?
  • Building Dynamic Classes in Objective C
  • Embed font in a mac bundle
  • NSString sizeWithAttributes: Inaccuracy
  • Attributed strings in UITableViewCells without WebView?
  • Printing an invisible NSView
  • target-action uicontrolevents
  • setSelectsInsertedObjects on NSArrayController not actually selecting
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk