ios - 如何为此日期格式化 NSDateFormatter

标签 ios swift nsdateformatter

我如何格式化 NSDateFormatter 以根据以下格式创建日期?

2015 年 5 月 16 日星期六 13:45:36

Sat May 16 的部分是我不确定该怎么做的部分

我知道最后一部分是 HH:mm:ss yyyy

最佳答案

let dateString = "Sat May 16 13:45:36 2015"
let df = NSDateFormatter()
df.dateFormat = "E MMM dd HH:mm:ss yyyy"
df.dateFromString(dateString)   // "May 16, 2015, 1:45 PM"

你应该看看这个 answer还有。

关于ios - 如何为此日期格式化 NSDateFormatter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30267649/

相关文章:

ios - 使用 selectedIndex 实例化 UITabBarViewController

objective-c - 使用 IB 的具有可见 subview 的透明 View

android - 发现flutter中任务 ':app:checkDebugManifest'(类型 'CheckManifest')的配置有问题

ios - 如何在 NSMutableAttributedString iOS Swift 3 中设置对齐方式

unit-testing - 如何在 Swift 中模拟单个函数?

swift - 如何在 UICollectionView 拖/放过程中删除 'ghost' 单元格,并使移动单元格不透明?

ios - 更改事件时区是否会影响共享事件中的其他人?

iOS Swift, "on my iPhone"文件夹的 url 是什么

ios - 80 年代的 4 月 1 日日期在 iOS 10.0 中无法解析

ios - NSDateFormatter格式化后错误的字符串