Moment.js get day name from date(Moment.js 从日期获取日期名称)
问题描述
我将 jquery 和 moment.js 用于自定义日历.
I'm using jquery and moment.js for a custom calendar.
我在变量 myDate
中有一个日期对象,例如:
I have a date object in a variable myDate
like :
Object { date="2014-12-23 14:00:00", timezone_type=3, timezone="Europe/Paris"}
我想,使用 moment.js(或不使用)获取此日期的日期名称,在我的示例中,我需要获取:tuesday
I want, using moment.js (or not) get the day name of this date, in my example i need to get : tuesday
想法?谢谢
推荐答案
现在你可以解析你拥有的日期字符串:
With moment you can parse the date string you have:
var dt = moment(myDate.date, "YYYY-MM-DD HH:mm:ss")
这是针对 UTC 的,如果您愿意,您必须从该点转换时区.
That's for UTC, you'll have to convert the time zone from that point if you so desire.
然后你可以得到星期几:
Then you can get the day of the week:
dt.format('dddd');
这篇关于Moment.js 从日期获取日期名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Moment.js 从日期获取日期名称


- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01