David K
David K

Reputation: 1

Using dateFormatter's on swift

var dateString = "Sat, 18 Jun 2016 11:00:00 +0900"

var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "E, d MMM yyyy HH:mm:ss Z"
var dateFromString = dateFormatter.dateFromString(dateString)

dateFormatter.locale = NSLocale(localeIdentifier: "ko_KR")
dateFormatter.dateStyle = .FullStyle
var dateFromStringToKorean = dateFormatter.stringFromDate(dateFromString!)

This code working in Playground.

but When I build this code in my iPhone it doesn't work.

Could you tell me what's the problem of this code.

Upvotes: 0

Views: 118

Answers (1)

Onur
Onur

Reputation: 194

Set locale property of dateFormatter before using it, as below:

var dateString = "Sat, 18 Jun 2016 11:00:00 +0900"

var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "E, d MMM yyyy HH:mm:ss Z"
dateFormatter.locale = NSLocale(localeIdentifier: "ko_KR")
dateFormatter.dateStyle = .FullStyle

var dateFromString = dateFormatter.dateFromString(dateString)
var dateFromStringToKorean = dateFormatter.stringFromDate(dateFromString!)

Upvotes: 1

Related Questions