NSDate for RFC 2822 Date Format

Is there an efficient way to convert NSDate to an RFC 2822 date format string? I want to use this line to create an NSURLRequest and set the value of the If-Modified-Since header field.

+4
source share
2 answers

try using NSDateFormatter

 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // maybe there exist a new-method now dateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss Z"; //RFC2822-Format NSString *dateString = [dateFormatter stringFromDate:myDate]; 
+16
source

Swift 3

 let rfcDateFormat = DateFormatter() rfcDateFormat.dateFormat = "EEE, dd MMM yyyy HH:mm:ss Z" let dateSTring = rfcDateFormat.string(from: Date()) //today result: Mon, 06 Feb 2017 17:21:18 +0100 
0
source

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


All Articles