How do I get the current Date in short format in Swift

前端 未结 7 811
北荒
北荒 2020-11-22 15:10

In the images below you can see the code I wrote and the values of all the variables:

class fun getCurrentShortDate() -> String {
    var todaysDate = NSD         


        
相关标签:
7条回答
  • 2020-11-22 16:11

    SWIFT 4 or 5

    extension Date {
    
     static func getCurrentDate() -> String {
    
            let dateFormatter = DateFormatter()
    
            dateFormatter.dateFormat = "dd/MM/yyyy HH:mm:ss"
    
            return dateFormatter.string(from: Date())
    
        }
    }
    

    Using

    print(Date.getCurrentDate())
    
    0 讨论(0)
提交回复
热议问题