js提取时间

//xx年yy月dd日 hh时mm分ss秒
function time(date){
	let time = new Date(date)
	const year =time .getFullYear();
	const month = time .getMonth()+1;
	const date = time .getDate();
	const hours = time .getHours()
	const minutes = time .getMinutes();
	const seconds = time .getSeconds();
	return year+"年"+month+"月"+date+"日"+hours+"时"+minutes+"分"+seconds+"秒";
}
//将毫秒数转化为xx时xx分
function(val){
	let h = Math.trunc((val/(1000*60*60)))//小时
    let m = Math.trunc((val%(1000*60*60)/(1000*60)))//分钟
    if(h>0){
      return `${h}小时${m}`
    }else{
      return `${m}`
    }}
//获取一周时间
function aWeek() {
      var now = new Date();
      var nowTime = now.getTime();
      var day = now.getDay();
      var oneDayTime = 24 * 60 * 60 * 1000;
      //显示周一
      var MondayTime = nowTime - (day - 1) * oneDayTime;
      //显示周日
      var SundayTime = nowTime + (7 - day) * oneDayTime;
      //初始化日期时间
      var monday = new Date(MondayTime);
      var sunday = new Date(SundayTime);
      if(monday){
        const year = monday.getFullYear();
        const month = monday.getMonth() + 1>9?monday.getMonth()+1:`0${monday.getMonth()+1}`;
        const date = monday.getDate()>9?monday.getDate():`0${monday.getDate()}`;
        let startTime = year + "-" + month + "-" + date + " " + "00" + ":" + "00" + ":" + "00";
        console.log(startTime);
      }
      if(sunday){
        const year = sunday.getFullYear();
        const month = sunday.getMonth() + 1>9?mosundaynday.getMonth()+1:`0${sunday.getMonth()+1}`;;
        const date = sunday.getDate()>9?sunday.getDate():`0${sunday.getDate()}`;
        let endTime =year + "-" + month + "-" + date + " " + "24" + ":" + "00" + ":" + "00";
        console.log(endTime);
      }
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值