如何在javascript中分割以下日期,
var date='2002-01-01';
The result should be as 20020101
谢谢..
答案 0 :(得分:6)
var date = "2002-01-01";
以下任一项都可以满足您的需求:
date = date.replace(/-/g, "");
date = date.split("-").join("");
答案 1 :(得分:4)
如果它只是一个字符串,你可以这样做:
var date = ("2002-01-02").replace(/-/g, "");
否则:
var now = new Date();
var date = now.getFullYear() + "" + (now.getMonth() + 1) + "" + now.getDate();