相关疑难解决方法(0)

是否可以在NSDateFormatter的格式字符串中添加自定义文本?

假设我希望日期看起来像这样:

|1988|December|30|
Run Code Online (Sandbox Code Playgroud)

如何将这些添加到dateFormatter或者为此让格式如下:

30 in the month of December in the year of 1998
Run Code Online (Sandbox Code Playgroud)

现在是1988年,12月和30年,我想使用标准格式,但我希望我提出的文字也随之而来.

特别是在上述情况下,格式和管道只是在日期或月份的日期格式旁边,格式和管道之间没有空格.

只需设置格式就可以实现这一切吗?

objective-c nsdateformatter ios

31
推荐指数
2
解决办法
6917
查看次数

NSDate在swift中设置了时区

如何从字符串返回预定义时区的NSDate

let responseString = "2015-8-17 GMT+05:30"
var dFormatter = NSDateFormatter()
dFormatter.dateFormat = "yyyy-M-dd ZZZZ"
var serverTime = dFormatter.dateFromString(responseString)
println("NSDate : \(serverTime!)")
Run Code Online (Sandbox Code Playgroud)

上面的代码返回时间为

2015-08-16 18:30:00 +0000
Run Code Online (Sandbox Code Playgroud)

nsdate swift

10
推荐指数
3
解决办法
4万
查看次数

标签 统计

ios ×1

nsdate ×1

nsdateformatter ×1

objective-c ×1

swift ×1