我想从我的 angularjs 项目中的 new Date()(当前日期) 获取日期格式的值。我在我的 javascript 文件中尝试以下代码:
var today = (new Date()).toISOString();
console.log(today.getDay());
Run Code Online (Sandbox Code Playgroud)
运行我的代码时,我收到此消息错误:
TypeError: today.getDay is not a function
Run Code Online (Sandbox Code Playgroud)
然而,这种语法有很多解决方案。请问我该如何修复它。任何帮助表示赞赏
用于getDay
对象Date
而不是 ISO 字符串:
var today = (new Date()).getDay();
Run Code Online (Sandbox Code Playgroud)
getDay
返回 0(星期日)到 6(星期六)之间的值。