javascript 使用 Jquery 从日期中获取星期几?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19882548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 17:08:25  来源:igfitidea点击:

Get the day of the week from a date using Jquery?

javascriptjquery

提问by GioBot

I now it has been aswer before, the problem is that I get the date from an input is not the current date.

我现在之前已经回答了,问题是我从输入中获取的日期不是当前日期。

I need to get the day of the week. Currently I get the date with this format :

我需要得到一周中的哪一天。目前我得到这种格式的日期:

11/09/2013

But I want it like:

但我想要它像:

Saturday/02/2013. 

I'm using datepicker to show the calendar, so it could be some solution that would help me using the same plugin.

我正在使用 datepicker 来显示日历,所以它可能是一些可以帮助我使用相同插件的解决方案。

回答by Hello World

var date = new Date();
var weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

var weekday = weekdays[date.getDay()];
var month = date.getMonth() + 1;
var year = date.getYear();