How to get timestamp from NSString date?

I have an NSString ( @"Mon, 01 Feb 2010 20:25:37 +0000") date that I want to change into a timestamp so that I can better calculate how much time has passed since the current time. How to change NSString date to timestamp value?

+1
source share
2 answers

Not fully verified this, but he has to do the trick.

NSDateFormatter *formatter = [[NSDateFormatter alloc] initWithDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ" allowNaturalLanguage:NO];
NSDate *date = [formatter dateWithString:@"Mon, 01 Feb 2010 20:25:37 +0000"];
+1
source

Use +[NSDate dateWithString:]if format is " 2001-03-24 10:45:32 +0600".

If not, you need to build NSDateFormatterand then use -[NSDateFormatter dateFromString:].

+1
source

Source: https://habr.com/ru/post/1734268/


All Articles