Files
supplier-dispatch-h5/src/utils/common.js

52 lines
1.5 KiB
JavaScript

const formatDate = date => {
let tempDate = new Date(date)
const year = tempDate.getFullYear()
const month = tempDate.getMonth() + 1
const day = tempDate.getDate()
return `${[year, month, day].map(formatNumber).join('-')}`
}
const formatDate1 = date => {
let value=date.replace(/\./g, '/')
let tempDate = new Date(value)
const year = tempDate.getFullYear()
const month = tempDate.getMonth() + 1
const day = tempDate.getDate()
return `${[year, month, day].map(formatNumber).join('/')}`
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${n}`
}
const leftCopy = (obj, source) => {
let sourceKey = Object.keys(source)
if (obj && source) {
Object.keys(obj).forEach(key => {
if (sourceKey.includes(key)) {
obj[key] = source[key] == null ? '' : source[key]
}
})
}
}
const timeFormat=(data) =>{
const currentDate = new Date(data);
const year = currentDate.getFullYear();
const month = String(currentDate.getMonth() + 1).padStart(2, '0');
const day = String(currentDate.getDate()).padStart(2, '0');
const hours = String(currentDate.getHours()).padStart(2, '0');
const minutes = String(currentDate.getMinutes()).padStart(2, '0');
const seconds = String(currentDate.getSeconds()).padStart(2, '0');
const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
// console.log("formattedDate",formattedDate)
return formattedDate;
}
module.exports = {
formatNumber,
formatDate,
leftCopy,
timeFormat,
formatDate1
}