当前位置 : 主页 > 网络编程 > 其它编程 >

JS日期和时间

来源:互联网 收集:自由互联 发布时间:2023-07-02
日期constnownewDate();console.log(now)WedMay25202223:37:32GMT0800(中国标准时间)console.log(typeo //日期 const now new Date(); console.log(now) Wed May 25 2022 23:37:32 GMT0800 (中国标准时间)console.log(typeof now) //object//年
日期constnownewDate();console.log(now)WedMay25202223:37:32GMT0800(中国标准时间)console.log(typeo

//日期 const now new Date(); console.log(now) Wed May 25 2022 23:37:32 GMT0800 (中国标准时间)console.log(typeof now) //object//年 月 日 时间console.log(getFullYear:,now.getFullYear()); //年console.log(getMonth:,now.getMonth()1);//月console.log(getDate:,now.getDate()); //日console.log(getDay:,now.getDay()); //星期几 0 等于星期天console.log(getHours:,now.getHours()); //时console.log(getDate:,now.getMinutes()); //分console.log(getSeconds:,now.getSeconds()); //秒//timestamps 时间戳 1970年 1月1日 - 当下console.log(timestamps,now.getTime());//日期字符串console.log(now.toDateString()); //Wed May 25 2022console.log(now.toTimeString()); //23:48:53 GMT0800 (中国标准时间)console.log(now.toLocaleString()); //打印本地计算机的时间

//日期 const now new Date(); const beforenew Date(February 1 2020 21:10:30);console.log(before.getTime(),now.getTime());//获取相差的天数 1000毫秒 1秒 const diffnow.getTime()-before.getTime();console.log(diff);//Math.round 四省五入const mins Math.round(diff/1000/60);const hoursMath.round(mins/60);const daysMath.round(hours/24);console.log(mins,hours,days);// 知道时间戳const timestamps1628882116160;console.log(new Date(timestamps));

//创建数字时钟

//日期 const clockdocument.querySelector(.clock);const tick()>{const now new Date();const hnow.getHours();const mnow.getMinutes();const snow.getSeconds();const html${h}:${m}:${s};clock.innerHTMLhtml;};setInterval(tick,1000);

day.js工具

【本文来源:美国服务器 https://www.68idc.cn 复制请保留原URL】
上一篇:leetcode_919.CompleteBinaryTreeInserter
下一篇:没有了
网友评论