Javascript基本日期格式化程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript基本日期格式化程序相关的知识,希望对你有一定的参考价值。

javascript Basic Date Formatter
  1. function DateFmt() {
  2. this.dateMarkers = {
  3. d:['getDate',function(v) { return ("0"+v).substr(-2,2)}],
  4. m:['getMonth',function(v) { return ("0"+v).substr(-2,2)}],
  5. n:['getMonth',function(v) {
  6. var mthNames = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
  7. return mthNames[v];
  8. }],
  9. w:['getDay',function(v) {
  10. var dayNames = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
  11. return dayNames[v];
  12. }],
  13. y:['getFullYear'],
  14. H:['getHours',function(v) { return ("0"+v).substr(-2,2)}],
  15. M:['getMinutes',function(v) { return ("0"+v).substr(-2,2)}],
  16. S:['getSeconds',function(v) { return ("0"+v).substr(-2,2)}],
  17. i:['toISOString',null]
  18. };
  19.  
  20. this.format = function(date, fmt) {
  21. var dateMarkers = this.dateMarkers
  22. var dateTxt = fmt.replace(/%(.)/g, function(m, p){
  23. var rv = date[(dateMarkers[p])[0]]()
  24.  
  25. if ( dateMarkers[p][1] != null ) rv = dateMarkers[p][1](rv)
  26.  
  27. return rv
  28. });
  29.  
  30. return dateTxt
  31. }
  32. }
  33.  
  34. fmt = new DateFmt()
  35. v = fmt.format(new Date(),"%w %d:%n:%y - %H:%M:%S %i")

以上是关于Javascript基本日期格式化程序的主要内容,如果未能解决你的问题,请参考以下文章

html PHP代码片段: - AJAX基本示例:此代码演示了使用PHP和JavaScript实现的基本AJAX功能。

javascript 性感日期测试片段

JavaScript sharepoint javascript日期格式化程序

sharepoint javascript日期格式化程序

JavaScript 代码片段

JavaScript 日期格式化 简单有用