Javascript基本日期格式化程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript基本日期格式化程序相关的知识,希望对你有一定的参考价值。
javascript Basic Date Formatter
function DateFmt() { this.dateMarkers = { d:['getDate',function(v) { return ("0"+v).substr(-2,2)}], m:['getMonth',function(v) { return ("0"+v).substr(-2,2)}], n:['getMonth',function(v) { var mthNames = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; return mthNames[v]; }], w:['getDay',function(v) { var dayNames = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]; return dayNames[v]; }], y:['getFullYear'], H:['getHours',function(v) { return ("0"+v).substr(-2,2)}], M:['getMinutes',function(v) { return ("0"+v).substr(-2,2)}], S:['getSeconds',function(v) { return ("0"+v).substr(-2,2)}], i:['toISOString',null] }; this.format = function(date, fmt) { var dateMarkers = this.dateMarkers var dateTxt = fmt.replace(/%(.)/g, function(m, p){ var rv = date[(dateMarkers[p])[0]]() if ( dateMarkers[p][1] != null ) rv = dateMarkers[p][1](rv) return rv }); return dateTxt } } fmt = new DateFmt() v = fmt.format(new Date(),"%w %d:%n:%y - %H:%M:%S %i")
以上是关于Javascript基本日期格式化程序的主要内容,如果未能解决你的问题,请参考以下文章
html PHP代码片段: - AJAX基本示例:此代码演示了使用PHP和JavaScript实现的基本AJAX功能。