小编Joe*_*erg的帖子

如果数字之间有逗号,则用 javascript 替换逗号

我试图替换每次出现的逗号“,”,但前提是它出现在两个数字/数字之间。

例如,“Text,10,10 text,40 text,10,60”应返回为“Text,1010 text,40 text,1060”,其中我替换在10,1010,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)

javascript regex replace

4
推荐指数
1
解决办法
1066
查看次数

Javascript如何在使用时区时通过getDay验证日期

我试图验证一周中的某一天是否等于星期三 (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)

javascript datetime

3
推荐指数
2
解决办法
1799
查看次数

标签 统计

javascript ×2

datetime ×1

regex ×1

replace ×1