当前位置:三九宝宝网 → 宝宝百科 → 宝宝知识 → 正文

javascript年月日格式输出时间

更新:03-16 整理:39baobao.com
字体:

[用C输入年月日怎样输出是第几周星期几急急急]#include<stdio.h> //#include<windows.h> int days[]={0,31,59,90,120,151,181,212,243,273,304,334,365}; int month[]={31,28,31,30,31,30,31,31,30,31,30,31}; char wee...+阅读

请参阅以下 javaScript 代码:

// 格式化显示日期时间

// 参数x : 待显示的日期时间,示例: new Date()

// 参数y: 需要显示的格式,示例:yyyy-MM-dd hh:mm:ss

function date2str(x, y) {

var z = {

y: x.getFullYear(),

M: x.getMonth() + 1,

d: x.getDate(),

h: x.getHours(),

m: x.getMinutes(),

s: x.getSeconds()

};

return y.replace(/(y+|M+|d+|h+|m+|s+)/g, function(v) {

return ((v.length > 1 ? "0" : "") + eval('z.' + v.slice(-1))).slice(-(v.length > 2 ? v.length : 2))

});

}调用示例:

alert(date2str(new Date(), "yyyy-MM-d h:m:s"));

这是js代码用来获取系统当前时间但就是出来效果

如何用javascript实现一个时钟