gpt4 book ai didi

javascript - 从 int 1-7 返回星期几

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:21:49 25 4
gpt4 key购买 nike

使用moment.js如何返回星期几?

我尝试了以下方法:

var i = 3;
moment(i).format('dddd');

预计周三返回,但没有成功。

最佳答案

你需要让 Moment 知道输入格式是什么。在您的情况下,输入格式是星期几,Moment 将其定义为 'e''E' 取决于您是否希望它以 0 索引与否:

moment(i, 'e').format('dddd') // if 0-6
moment(i, 'E').format('dddd') // if 1-7
Input Example Description
e 0..6 Locale day of week
E 1..7 ISO day of week

– Moment's documentation on Week year, week, and weekday tokens.

关于javascript - 从 int 1-7 返回星期几,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40634005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com