Swift|Swift DateFormatter
Thursday, Mar 17, 2016
let dateFormate = DateFormatter()
dateFormate.dateFormat = "EEEE, MMM d, yyyy"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
【Swift|Swift DateFormatter】03/17/2016
let dateFormate = DateFormatter()
dateFormate.dateFormat = "MM/dd/yyyy"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
03-17-2016 07:10
let dateFormate = DateFormatter()
dateFormate.dateFormat = "MM-dd-yyyy HH:mm"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
Mar 17, 7:10 AM
let dateFormate = DateFormatter()
dateFormate.dateFormat = "MMM d, H:mm a"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
March 2016
let dateFormate = DateFormatter()
dateFormate.dateFormat = "MMMM yyyy"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
17.03.16
let dateFormate = DateFormatter()
dateFormate.dateFormat = "dd.MM.yy"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
Mar 17, 2016
let dateFormate = DateFormatter()
dateFormate.dateFormat = "MMM d, yyyy"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
Thu, 17 Mar 2016 07:10:30 -0500
let dateFormate = DateFormatter()
dateFormate.dateFormat = "E, d MMM yyyy HH:mm:ss Z"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
2016-03-17T07:10:30-0500
let dateFormate = DateFormatter()
dateFormate.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
NSDateFormatterStyle
3/17/16 (ShortStyle )
let dateFormate = DateFormatter()
dateFormate.dateStyle = .shortStyle
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
Mar 17, 2016, 6:12:30 PM ( MediumStyle )
let dateFormate = DateFormatter()
dateFormate.dateStyle = .mediumStyle
dateFormate.timeStyle = .mediumStyle
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
March 17, 2016 at 6:14:36 PM GMT+5:30 (LongStyle )
let dateFormate = DateFormatter()
dateFormate.dateStyle = .longStyle
dateFormate.timeStyle = .longStyle
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
Thursday, March 17, 2016 (FullStyle)
let dateFormate = DateFormatter()
dateFormate.dateStyle = .fullStyle
let date = Date()
let stringOfDate = dateFormate.string(from: date)
print(stringOfDate)
推荐阅读
- Swift中willSet和didSet的简述
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- LeetCode算法题-11.|LeetCode算法题-11. 盛最多水的容器(Swift)
- iOS-Swift-map|iOS-Swift-map filter reduce、函数式编程
- Swift|Swift ----viewController 中addChildViewController
- SwiftUI|SwiftUI iOS 瀑布流组件之仿CollectionView不规则图文混合(教程含源码)
- Swift高级应用|Swift高级应用 -01
- Swift5.0|Swift5.0 UITexview的基本使用
- Swift7|Swift7 - 循环、函数
- Swift学习笔记(三)Alamofire二次封装