3

I am having problem finding date from string that is formatted using NSDateFormatter

Now, I am using this code:

NSDate *afterDate=[NSDate dateWithNaturalLanguageString:balanceDateAfter.stringValue];

This code returning date with GeorgianCalendar format but I want it in PersianCalendar.

I think if I use this code :

NSDate *afterDate=[NSDate dateWithNaturalLanguageString:balanceDateAfter.stringValue locale:];

It will return true date format but I don't know how can I use locale to set appropriate date formatter ( or my system locale ).


balanceDateAfter in above codes is an NSTextfield with NSDateFormatter.

Prooshani
  • 534
  • 7
  • 20

1 Answers1

1

NSDates do not have a calendar. An NSDate represents an absolute moment in time as defined by the difference between that moment and the first instant of 1st January 2001 in GMT. Basically, it's a positive or negative number of seconds, nothing more.

If you have an appropriate formatter assigned to the text field, you should get its value using -objectValue, not -stringValue. That way, you will be given the NSDate directly and you won't need to parse the string yourself.

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • Wow, thank you dude !boooom, My problem solved. Thank you so much +1 `NSDate *afterDate=[balanceDateAfter objectValue];` – Prooshani Jul 08 '11 at 19:37