0

This is the timestamp I am trying to get my app to read: Thu, 03 Mar 2016 16:06:42 GMT

This is the closest I have, but haven't had any success:

[df setDateFormat:@"EEE, dd MMM YYYY HH:mm:ss z"];

EDIT: My current format prints-to/reads: Tue, 02 M02 2016 11:36:57 GMT-5

is there anything I'm missing?

Final Edit:

I should have just posted all my code...

    [df setLocale:[NSLocale systemLocale]];

This was messing things up for me.

Jargen89
  • 480
  • 1
  • 6
  • 19
  • If you are looking for GMT, it has been answered here http://stackoverflow.com/questions/9024274/getting-the-correct-gmt-format-using-dateformat-object – SwiftArchitect Feb 02 '16 at 16:29

2 Answers2

2

I believe your year is incorrect. Change your dateformat to

[df setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z"];

See documentation on formatter dates here

Devster101
  • 578
  • 4
  • 18
1

I tried to use your date format and convert it to a nsdate and back to a string. It should work with the format string you used.

let time = "Thu, 03 Mar 2016 16:06:42 GMT"
let dateformat = "EEE, dd MMM yyyy HH:mm:ss z"

var dateformatter = NSDateFormatter()
dateformatter.dateFormat = dateformat
dateformatter.timeZone = NSTimeZone(forSecondsFromGMT: 0)

var date = dateformatter.dateFromString(time)

var newTime = dateformatter.stringFromDate(date!)
// newTime = "Thu, 03 Mar 2016 16:06:42 GMT"

Edit: I changed the dateformat to use lowercase ys for the year as suggested by Devster101. This is the correct format according to this spezification which is used since iOS 7

Dominic Krause
  • 112
  • 1
  • 10