简体   繁体   中英

using NSDate to find the DATE from string

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.

NSDate s 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM