<script type= "Text/javascript" >/** * string turn time format; */function FormatDate (date, format) {if (date.length==0) return; if (!format) format = "YYYY-MM-DD"; Switch (typeof date) {case "string": Date = new Date (Date.replace (/-/, "/")); Break Case "Number": Date = new Date (date); Break } if (!date instanceof date) return; var dict = {"yyyy": date.getfullyear (), "M": Date.getmonth () + 1, "D": date.getdate (), "H": date.gethours (), "M": date.getminutes (), "s": Date.getseconds (), "MM": ("" + (DAT E.getmonth () + 101)). substr (1), "DD": ("" + (Date.getdate () +)). substr (1), "HH": ("" + (Date.getho Urs () + +). substr (1), "MM": ("" + (Date.getminutes () +)). substr (1), "SS": ("" + (Date.getsecond S () + ()). substr (1)}; Return Format.replace (/(yyyy| Mm?| dd?| hh?| ss?| MM?) /g, function () {return dict[arguments[0]]; }); } $ (function () {$ ("#otherPublishDate"). HTML (formatdate ("2010-04-30", "yyyy mm DD");}); </script>
JS format string Date format