javascript - 如何从 html 表列中包含的日期中提取月份?

标签 javascript html

我有一个 html 表格。一列包含日期值。我想提取那些 datesmonth 并将其打印在控制台中。日期格式为 yyyy-MM-dd。这是我的代码:

var myTable = document.getElementById('openDispatchNoteTable');

for (var i = 0 ; i < myTable.rows.length ; i++) {
    console.log("date : " + myTable.rows[i].cells[6].innerText);
}

myTable.rows[i].cells[6].innerText2018-November-14 作为输出。

你能帮我解决这个问题吗?

最佳答案

如果所有输出的格式都相同 - 然后使用正则表达式 .innerText.match(/[a-z]+/i)[0]

console.log(document.querySelector('div').innerText.match(/[a-z]+/i)[0])
<div>2018-November-14</div>

我还在这里找到了很好的国际化解决方案:get month name from date第二个最佳答案使用 toLocaleString

关于javascript - 如何从 html 表列中包含的日期中提取月份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53391453/

相关文章:

html - 顶部 DIV 大小适合内容 - 底部 DIV 滚动并使剩余空间适合窗口

java - 我应该把我的 css 文件放在 Intellij IDEA 的什么地方

javascript - 加载我的像素后我的 div 不存在

javascript - JS/正则表达式 : Remove a substring from end of string with optional comma and spaces in front and dot behind

javascript - if else 变量作用域在 js 的 else 中显示未定义

javascript - AngularJS - ng-include View Controller 中的服务变量更改不会传播到父 Controller

javascript - 计算其他时空之间的时间更新

javascript - 将复选框值存储在 webix 的 cookie 中

javascript - 我可以在 Vue 中使用带有箭头函数的样式绑定(bind)吗?

javascript - 使用 AngularJS d3 处理 JSON 数据