The time that the database is fetched to do is generally: Thu Nov 18:29:21 gmt+0800 This format
When using JST to dynamically render the template, this will be output directly to the page by string, so you need to convert the time into a normal 2010-10-10 format
There are two ways to solve, one is by the outside of the JS conversion method as a parameter in the form of directly into the rendering parameters, such as:
var change = function (time) {...} var param = {' Change ': change};
So in the JST template, you need to write
{var timestr = change (_item.date)} ${timestr}
Another recommended way to do this is to use the JS method as a custom identifier, so that the JST template requires only the following:
${_item.date|changetime}
You can complete the automatic conversion, the specific JS code:
var mymodifiers = {Timeformat:function (thisvalue) {return changestrtoformattimestr (Thisvalue);}}; var arr = function (ARG) {return getloops (arg,true);} var param = {' result ': result, ' func ': arr}; if (Null = result) {param = {"Result": "", "Func": arr};} Param._modifiers = mymodifiers; $ ("Commentshowdiv"). InnerHTML = Trimpath.parsetemplate ($ ("commentdivhtml"). Value). process (param);
//converts a time series to a specific Format function Changestrtoformattimestr (TIMESTR) {return formattime totime (timestr), "Yyyy-mm-dd HH: MM "); }//String converted to TIME function ToTime (s) {var converted = Date.parse (s); var mydate = new Date (converted); if (isNaN (mydate)) {VA R arys= S.split ('-'); MyDate = new Date (Arys[0],--arys[1],arys[2]); return mydate; }//Time format conversion function Formattime (DATE,FORMATSTR) {var str = formatstr; var Week = [' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ']; STR=STR.R Eplace (/yyyy| Yyyy/,date.getfullyear ()); Str=str.replace (/yy| yy/, (date.getyear ()%) >9? (Date.getyear ()%). ToString (): ' 0 ' + (date.getyear ()% 100)); Str=str.replace (/mm/,date.getmonth () >9?date.getmonth (). toString (): ' 0 ' + date.getmonth ()); Str=str.replace (/m/g,date.getmonth ()); Str=str.replace (/w| W/g,week[date.getday ()]); Str=str.replace (/dd| Dd/,date.getdate () >9?date.getdate (). toString (): ' 0 ' + date.getdate ()); Str=str.replace (/d| D/g,date.getdate ()); Str=str.replace (/hh| Hh/,date.gethours () >9?date.gethours (). toString (): ' 0 ' + date.GetHours ()); Str=str.replace (/h| H/g,date.gethours ()); Str=str.replace (/mm/,date.getminutes () >9?date.getminutes (). toString (): ' 0 ' + date.getminutes ()); Str=str.replace (/m/g,date.getminutes ()); Str=str.replace (/ss| Ss/,date.getseconds () >9?date.getseconds (). toString (): ' 0 ' + date.getseconds ()); Str=str.replace (/s| S/g,date.getseconds ()); return str; }