/** output specified time format description for 2014.09.05 13:14:20yyyy: Year, 2014yy: year, 14MM: month, fill two bits, 09M: month, 9dd: date, fill two digits, 05d: date, 5hh:24 hours, fill Full two-bit, 13h:24-hour, 13hh:12-hour, two-bit, 01h:12-hour, 1mm: minutes, two-bit, 14m: minutes, 14ss: seconds, fill two-bit, 20s: seconds, 20w: Week, for [' Day ', ' one ', ' two ', ' three ', ' four ', ' five One of ' Six ', this demo result is five e.g.formatdate (new Date (1409894060000), ' Yyyy-mm-dd HH:mm:ss week W ') 2014-09-05 13:14:20 Friday */func tion formatdate (t, str) {var obj = {yyyy:t.getfullyear (), yy: ("" + t.getfullyear ()). Slice ( -2), M:t.getmonth () +1,mm: ("0" + (T.getmonth () +1)). Slice ( -2), d:t.getdate (), DD: ("0" +t.getdate ()). Slice ( -2), h:t.gethours (), HH: ("0" +t.gethours ()). Slice ( -2), H: T.gethours ()% 12,hh: ("0" + (t.gethours ()%12)). Slice ( -2), m:t.getminutes (), MM: ("0" +t.getminutes ()). Slice ( -2), S: T.getseconds (), SS: ("0" +t.getseconds ()). Slice ( -2), w: [' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' Six '][t.getday ()]};return Str.replace (/([a-z]+)/ig, function ($) {return obj[$1];}); Console.log (FormatDate (New Date (), ' Yyyy-mm-dd HH:mm:ss week W '));
JavaScript Date dates formatted formatdate