In fact, we are on the display of the date, there are a few, do not need to pass the format of the string each time.
Just tell the function what you want, and here's my new date formatting function in JavaScript in iOS:
1 /** 2 formatted Date3 @param {string} formatstr-formatted string4 @description5 "Date": Displays the date. For example: 2017/09/096 "Time": Displays the Times. For example: 15:09:057 "Minute": displayed to minutes. such as: 2017/09/09 15:098 "Second" is displayed to seconds. such as: 2017/09/09 15:09:059 @return {String} date after formattingTen */ OneDate.prototype.format =function(formstr) { A varDate = This; - varYear,month,day,hour,minute,second; - varDatestr,minutestr,secondstr; the -Year=date.getfullyear (); Month=date.getmonth (+1); day=date.getdate (); - -datestr=year+ "/" + (month<10? ") 0 "+month:month" + "/" + (day<10? ") 0 "+day:day); + if(formstr== "Date")returnDatestr; - +Hour=date.gethours (); Minute=date.getminutes (); Second=date.getseconds (); A atMinutestr= (hour<10? ") 0 "+hour:hour" + ":" + (minute<10? ") 0 "+minute:minute); -secondstr=minutestr+ ":" + (second<10? ") 0 "+second:second); - if(formstr== "Time")returnSecondstr; - - if(formstr== "Minute")returndatestr+ "" +Minutestr; - in if(formstr== "Second")returndatestr+ "" +Secondstr; -};
Very low is very real.
A new idea for formatting dates in JavaScript.