3 Star 2 Fork 3

yichen / js常用工具

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Download.ts 1020 Bytes
一键复制 编辑 原始数据 按行查看 历史
yichen 提交于 2024-05-20 11:06 . 更新ts支持
// 下载文件
export function downloadFile(obj : any, name : any, suffix : any) {
const url = window.URL.createObjectURL(new Blob([obj]))
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
const fileName = parseTime(new Date()) + '-' + name + '.' + suffix
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
export default { downloadFile }
function parseTime(date : Date) {
date = date || new Date;
var year:any = date.getFullYear()
var month:any = date.getMonth() + 1
var day:any = date.getDate();
// 因为当年月日中间是 ‘-’ 短横线的时候,它的解析是用UTC 时区处理,而不是用本地时区处理的,因此相差八个小时,就成了这个时间点到1970年1月1日08:00的毫秒数。
// 解决办法就是将日期中的短横线替换成 ‘/’ ,
// getTime()和Date.parse()方法 都会有相同的情况
return Date.parse(year + '-' + month + '-' + day);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/wokaixin/yc.git
git@gitee.com:wokaixin/yc.git
wokaixin
yc
js常用工具
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891