shangfutong-ui/jeepay-ui-uapp-agent/util/timeInterval.js

14 lines
544 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export function getDay(num, str) {
//如果要获取昨天的日期num就是-1 前天的就是-2依次类推。str表示年月日间的分割方式。
const today = new Date()
const nowTime = today.getTime()
const ms = 24 * 3600 * 1000 * num
today.setTime(nowTime + ms)
const oYear = today.getFullYear()
let oMoth = (today.getMonth() + 1).toString()
if (oMoth.length <= 1) oMoth = "0" + oMoth
let oDay = today.getDate().toString()
if (oDay.length <= 1) oDay = "0" + oDay
return oYear + str + oMoth + str + oDay
}