使用 JavaScript 从时间戳获取星期几

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5634403/
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-25 17:51:05  来源:igfitidea点击:

Getting day of the week from timestamp using JavaScript

javascriptdate

提问by Pidoaisn

How do I get the day of the week from a timestamp in JavaScript? I'd like to get this from a timestamp I specify, not the current date.

如何从 JavaScript 中的时间戳获取星期几?我想从我指定的时间戳中获取它,而不是当前日期。

Thanks

谢谢

采纳答案by Teneff

var timestamp = 654524560; // UNIX timestamp in seconds
var xx = new Date();
xx.setTime(timestamp*1000); // javascript timestamps are in milliseconds
document.write(xx.toUTCString());
document.write(xx.getDay()); // the Day

回答by klidifia

var timestamp = 1400000000;
var a = new Date(timestamp*1000);
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var dayOfWeek = days[a.getDay()]

Now the "day of the week" is in the dayOfWeek variable.

现在“星期几”在 dayOfWeek 变量中。

回答by Ammu

Try out the following:

尝试以下操作:

var currentTime = new Date();
var day = currentTime.getDate();