最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Moment js Not returning the right day of the week - Stack Overflow

programmeradmin2浏览0评论

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"). 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')
I've also tried using moment().days('3').format('ddd')
Always returns the same day. Usually Sat or Mon.

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"). 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')
I've also tried using moment().days('3').format('ddd')
Always returns the same day. Usually Sat or Mon.

Share Improve this question asked Aug 26, 2013 at 14:23 JohnstonJohnston 20.9k22 gold badges76 silver badges124 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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"];
发布评论

评论列表(0)

  1. 暂无评论