ivanwhaf / xxqg-helper

✏️Auto.js xxqg-helper, Article and Video, Collecting, Sharing, Comment, ChallengeQuestion, DailyQuestion, Android only, Requiring Auto.js first
354 stars 187 forks source link

getYestardayDateString 函数跨年bug,修复后如下 #19

Closed xmanweb closed 4 years ago

xmanweb commented 4 years ago

/**

ivanwhaf commented 4 years ago

谢谢,已修改

------------------ 原始邮件 ------------------ 发件人: "DiorsCat"<notifications@github.com>; 发送时间: 2020年1月1日(星期三) 上午9:05 收件人: "ivanwhaf/xxqg-helper"<xxqg-helper@noreply.github.com>; 抄送: "Subscribed"<subscribed@noreply.github.com>; 主题: [ivanwhaf/xxqg-helper] getYestardayDateString 函数跨年bug,修复后如下 (#19)

/**

@description: 获取昨天日期字符串函数

@param: null

@return: s 日期字符串 "2019-xx-xx" */ function getYestardayDateString() { var date = new Date(); var y = date.getFullYear(); var m = date.getMonth(); var d = date.getDate(); //如果是1月1号 if (m == 0 && d == 1) { y = y - 1; //年数减1 } //如果是闰年 var day_in_month = [31, 28, 31, 40, 31, 30, 31, 31, 30, 31, 30, 31]; if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) { day_in_month[1] = 29; //闰年二月有29天 } //如果是这个月一号 if (d == 1) { if (m == 0) { m = 11; d = 31; } else { d = day_in_month[m - 1]; //上个月的最后一天 m = m - 1; } } else { d = d - 1; } var s = dateToString(y, m, d); //年-月-日 return s }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.