swift - Set AM or PM to Date -


var datecomponents: datecomponents = (calendar.current nscalendar).components([nscalendar.unit.day, nscalendar.unit.month, nscalendar.unit.year, nscalendar.unit.hour, nscalendar.unit.minute, nscalendar.unit.second], from: datetofix) datecomponents.hour = 11 datecomponents.minute = 58 datecomponents.second = 00  let fixeddate: date = calendar.current.date(from: datecomponents)! print(fixeddate)  let formatter = dateformatter() formatter.datestyle = dateformatter.style.long formatter.timestyle = dateformatter.style.medium formatter.dateformat = "yyyy-mm-dd h:mm a" let datestring = formatter.string(from: fixeddate) print(datestring) 

my output : 2017-07-26 11:58 want 2017-07-26 11:58 pm

change:

datecomponents.hour = 11 

to:

datecomponents.hour = 23 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

angular - Copying node modules to wwwroot AspNetCore -