ios - how to add Hours to date in swift in this format "2015-06-11T00:00:00.000Z" as in one string while parsing in SWIFT -


how add hours date in swift in format "2015-06-11t00:00:00.000z" in 1 string while parsing in swift.

i trying add time date in ons string parsing in swift. have 2 texfields representing date , time date picker, when parse string date displays. want combine date , time in string , send server. please me in swift language

you can using nscalendar method datebysettinghour follow:

xcode 8.2.1 • swift 3.0.2

let df = dateformatter() df.calendar = calendar(identifier: .iso8601) df.locale = locale(identifier: "en_us_posix") df.dateformat = "yyyy-mm-dd't'hh:mm:ss.sss'z" if let date = df.date(from:"2015-06-11t00:00:00.000z") {     let hour = 4     if let datewithtime = calendar.current.date(bysettinghour: hour, minute: 0, second: 0, of: date) {         let resultstring = df.string(from: datewithtime)         print(resultstring) // "2015-06-11t04:00:00.000z"     } } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -