简体   繁体   English

如何从moment.js获取两位数的星期数?

[英]How can I get a two digit week number from moment.js?

I have the following code: 我有以下代码:

var currentYear = moment().isoWeekYear().toString();
var currentWeek = moment().isoWeek().toString();
var endYear = moment().add(24, 'weeks').isoWeekYear().toString();
var endWeek = moment().add(24, 'weeks').isoWeek().toString();

This gives me 201734 - 20186 but I need 201734 - 201806 (the last 06). 这给了我201734 - 20186但我需要201734 - 201806 (最后一个06)。 See fiddle . 见小提琴

I can of course check if week is < 10 and add a 0 to the string. 我当然可以检查week是否小于10,并将0添加到字符串中。 But is there a way to format this using moment.js? 但是有没有一种方法可以使用moment.js格式化呢?

I tried using var currentWeek = moment().isoWeek().format('ww').toString() but that didn't work well. 我尝试使用var currentWeek = moment().isoWeek().format('ww').toString()但效果不佳。

使用它来获取两位数字的周号: moment(new Date()).format('WW')

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

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