我试图替换每次出现的逗号“,”,但前提是它出现在两个数字/数字之间。
例如,“Text,10,10 text,40 text,10,60”应返回为“Text,1010 text,40 text,1060”,其中我替换在10,10和10,60之间找到的逗号,但保留逗号正文之后。
var text = "Text, 10,10 text, 40 text, 10,60";
var nocomma = text.replace(/,/g, '');
console.log(nocomma);Run Code Online (Sandbox Code Playgroud)
我试图验证一周中的某一天是否等于星期三 (3),如果我按以下方式操作,这很有效。
var today = new Date();
if (today.getDay() == 3) {
alert('Today is Wednesday');
} else {
alert('Today is not Wednesday');
}Run Code Online (Sandbox Code Playgroud)
但我无法对时区做同样的事情。
var todayNY = new Date().toLocaleString("en-US", {timeZone: "America/New_York"});
if (todayNY.getDay() == 3) {
alert('Today is Wednesday in New York');
} else {
alert('Today is not Wednesday in New York');
}Run Code Online (Sandbox Code Playgroud)