简体   繁体   English

Moment js不返回星期几

[英]Moment js Not returning the right day of the week

I am trying to use Momentjs to return the day of the week (ex. "monday" or "mon", doesn't matter as long as it's the name of the day of the week) for the string number that I stored in the db (ex "3" ). 我正在尝试使用Momentjs返回星期几(例如“ monday”或“ mon”,没关系,只要它是星期几的名称)即可存储在db(例如"3" )。 For some reason I keep getting Monday returned. 由于某种原因,我一直在返回星期一。

var values = ["3", "06:00", "18:00"];
moment().isoWeekday(values[0]).format('ddd');
//returns "Mon"

I've also tried using moment('3','d').format('ddd') 我也尝试过使用moment('3','d').format('ddd')
I've also tried using moment().days('3').format('ddd') 我也尝试过使用moment().days('3').format('ddd')
Always returns the same day. 一律返回同一天。 Usually Sat or Mon. 通常是星期六或星期一。

try 尝试

moment().isoWeekday(parseInt(values[0])).format('ddd');

And in general, store the week day as integer and not string: 通常,将工作日存储为整数而不是字符串:

var values = [3, "06:00", "18:00"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM