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

javascript - Create Date in Moment.js - Stack Overflow

programmeradmin1浏览0评论

I am not seeing it in the documentation but I am wondering if I can do something similar like in C#

DateTime d = new DateTime(2019,01,01);

I would like to do that with moment

var d = moment(2019,01,01);

but that does not seem to work.

I can see I could do something like

var d = momment('2019-01-01');

but I want to do it separately so I can do something like

Datetime d = new DateTime(now.Year + 1, 01, 01);

I am not seeing it in the documentation but I am wondering if I can do something similar like in C#

DateTime d = new DateTime(2019,01,01);

I would like to do that with moment

var d = moment(2019,01,01);

but that does not seem to work.

I can see I could do something like

var d = momment('2019-01-01');

but I want to do it separately so I can do something like

Datetime d = new DateTime(now.Year + 1, 01, 01);
Share Improve this question asked Aug 9, 2019 at 21:45 chobo2chobo2 85.8k207 gold badges551 silver badges861 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

You can use following constructor:

var d = moment({ year: 2019, month: 1, day: 1});

Or:

var d = moment([2019, 1, 1]);

You can just use a Template Literal to inject your variables into the moment argument string:

let date = moment(`${moment().year()}-01-01`).add(1, 'years');
发布评论

评论列表(0)

  1. 暂无评论