当前位置:网站首页>JS gets the year, month, day, time, etc. of the simple current time
JS gets the year, month, day, time, etc. of the simple current time
2022-08-10 04:29:00 【weixin_43923808】
var date = new Date();date .getYear(); //Get the current year (2 digits)date .getFullYear(); //Get the full year (4 digits)date .getMonth(); //Get the current month (0-11, 0 represents January)date .getDate(); //Get the current day (1-31)date .getDay(); //Get the current week X (0-6, 0 represents Sunday)date .getTime(); //Get the current time (the number of milliseconds since 1970.1.1)date .getHours(); //Get the current hour (0-23)date .getMinutes(); //Get the current minute (0-59)date .getSeconds(); //Get the current number of seconds (0-59)date .getMilliseconds(); //Get the current number of milliseconds (0-999)date .toLocaleDateString(); //Get the current datevar mytime=date .toLocaleTimeString(); //Get the current timedate .toLocaleString( ); //Get the date and time// get the current monthvar nowMonth = date.getMonth() + 1;// Get the current numbervar strDate = date.getDate();// add separator "-"var seperator = "-";// Process the month, add a "0" in front of the month from January to Septemberif (nowMonth >= 1 && nowMonth <= 9) {nowMonth = "0" + nowMonth;}// Process the month, add a "0" in front of the 1-9if (strDate >= 0 && strDate <= 9) {strDate = "0" + strDate;}// Finally concatenate the string to get a date in the format (yyyy-MM-dd)var nowDate = date.getFullYear() + seperator + nowMonth + seperator + strDate;// get the previous day's datevar time = (new Date).getTime() - 24 * 60 * 60 * 1000;var yesday = new Date(time); // get the previous day's date
边栏推荐
猜你喜欢
随机推荐
order by注入与limit注入
LeetCode·301.删除无效的括号·BFS
链表的定义和使用
TCP协议之《ACK报文限速》
【Web3 系列开发教程——创建你的第一个 NFT(7)】创建一个 NFT DApp,给你的 NFT 赋予属性,例如图片
MySQL事务的保证机制
微信公众号开发
Flink CDC介绍和个人理解
Kubernetes资源编排系列之一: Pod YAML篇
释放高通量算力价值潜能 JASMINER持续领跑 Web3 市场
机器学习之聚类——双聚类简介及简单案例
关于rust的mongodb驱动count方法无法与near条件一同使用的问题
【Mindspore】【310推理】导入mindir文件出错
[crit] 23856#0: *101796511 stat()
TCP协议之《发送缓存控制tcp_notsent_lowat》
webrtc学习--websocket服务器
PHPCMS仿站从入门到精通,小白看这一套课程就够了
TCP协议之《TCP_CORK选项》
基于Nonebot2的qq机器人如何测试超管账号
wind7 无法安装tools (问题已解决)