wrong date

Hi Developer's

get following wrong Date from string

extension DateFormatter { convenience init(dateFormat: String) { self.init() self.locale = Locale.current self.timeZone = TimeZone.current self.dateFormat = dateFormat } }

extension Date{ func getCurrentTimestamp()->String{ let formatter = DateFormatter() formatter.timeZone = TimeZone.current formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" return(String(describing:formatter.string(from: self))) } }

let dateFormatter = DateFormatter(dateFormat: "HH:mm") let myDate = dateFormatter.date(from: "10:30")

print myDate 2000-01-01 08:55:00 +0000

print TimeZone,current "Europe/Berlin"

print Locale.current.description "de_DE (current)"

print Date().getCurrentTimeStamp() 2018-10-14 03:56:23"

what is going on here... :O :O

on last Verion of Xcode and Beta too

thank's for any suggestions

Edit: https://datingexpat.fun/

When you show your code, please use the code block? What is wrong with 2000-01-01 08:55:00 +0000? What is wrong with 2018-10-14 03:56:23? And what are the expected outputs?

When you post code, please post real code (this is not) and use code formatter tool.

extension DateFormatter {
    convenience init(dateFormat: String) {
        self.init()
        self.locale = Locale.current
        self.timeZone = TimeZone.current
        self.dateFormat = dateFormat
    }
}

extension Date {
    func getCurrentTimestamp()->String{
        let formatter = DateFormatter()
        formatter.timeZone = TimeZone.current
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        return(String(describing:formatter.string(from: self)))
    }
}

let dateFormatter = DateFormatter(dateFormat: "HH:mm")
let myDate = dateFormatter.date(from: "10:30")
print(myDate) // 2000-01-01 08:55:00 +0000
print(TimeZone.current)// "Europe/Berlin"
print(Locale.current.description)// "de_DE (current)"
print (Date().getCurrentTimestamp())// 2018-10-14 03:56:23"

Explain also clearly the problem.

With this code I get:

  • Optional(2000-01-01 09:30:00 +0000)
  • Europe/Paris (fixed (equal to current))
  • en_US (current)
  • 2021-10-13 17:43:40

not 2018 year

wrong date
 
 
Q