遇到日期转换问题:
js中将斜杠\替换的方法
js中将/替换的方法 replace(///g, ‘-’) 全局替换
js 显示当前日期加时间(如:2018-06-12 12:00)
function currentTime() {
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var clock = year + "-";
if(month < 10)
clock += "0";
clock += month + "-";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm;
return(clock);
}
本文介绍了在JavaScript中如何进行日期格式的转换,包括将斜杠替换为其他字符的方法,以及如何显示包含当前日期和时间的字符串。通过具体函数实例,展示了如何获取年、月、日、时、分,并将其格式化为标准的日期时间格式。
1907

被折叠的 条评论
为什么被折叠?



