js format date

您所在的位置:网站首页 js将字符串转为对象 js format date

js format date

2023-05-02 07:34| 来源: 网络整理| 查看: 265

将字符串形式的日期转换成日期对象

var strTime="2011-04-16"; //字符串日期格式 var date= new Date(Date.parse(strTime.replace(/-/g, "/"))); //转换成Date();

var month=date.getMonth()+1; //获取当前月份

date.getYear(); //获取当前年份(2位) date.getFullYear(); //获取完整的年份(4位,1970-????) date.getMonth(); //获取当前月份(0-11,0代表1月) date.getDate(); //获取当前日(1-31) date.getDay(); //获取当前星期X(0-6,0代表星期天) date.getTime(); //获取当前时间(从1970.1.1开始的毫秒数) date.getHours(); //获取当前小时数(0-23) date.getMinutes(); //获取当前分钟数(0-59) date.getSeconds(); //获取当前秒数(0-59) date.getMilliseconds(); //获取当前毫秒数(0-999) date.toLocaleDateString(); //获取当前日期 var mytime=date.toLocaleTimeString(); //获取当前时间 date.toLocaleString( ); //获取日期与时间



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3