我有一个变量,其日期值为 YYYYMM 格式。例如:
var givenDate = "201704"
如何找出给定月份的最后一天并附加到它。例如,
//last day of 2017 04 (April) is 30th so append value to givenDate + lastDate;
//that will be 20170430
var newFullGivenDate = "20170430";
最佳答案
const date = "201704";
const year = parseInt(date.substring(0, 4));
const month= parseInt(date.substring(4, 6));
const lastDay = (new Date(year, month, 0)).getUTCDate();
const newFullGivenDate = date + lastDay;
console.log(newFullGivenDate);
关于javascript - 以 YYYYMM 日期格式设置月份的最后一天 - Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43744771/