获取当地时间
Posted 静静的fire
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取当地时间相关的知识,希望对你有一定的参考价值。
1 var date = new Date(), 2 year = date.getFullYear(), 3 month = date.getMonth() + 1,//从0开始 4 day = date.getDate(), 5 week = date.getDay(),//0表示星期日 6 hour = date.getHours(), 7 minute = date.getMinutes(), 8 second = date.getSeconds(), 9 time = date.toLocaleDateString(),//当前日期Tuesday, September 26, 2017 10 timer = date.toLocaleString(),//日期与时间Tue Sep 26 2017 22:23:18 GMT+0800 (中国标准时间) 11 times = date.toLocaleTimeString();//时间22:23:18 12 switch(week){ 13 case 1:week = ‘星期一‘;break; 14 case 2:week = ‘星期二‘;break; 15 case 3:week = ‘星期三‘;break; 16 case 4:week = ‘星期四‘;break; 17 case 5:week = ‘星期五‘;break; 18 case 6:week = ‘星期六‘;break; 19 case 0:week = ‘星期日‘;break; 20 default:break; 21 }; 22 minute = minute <= 9 ? (‘0‘+1) : minute; 23 second = second <= 9 ? (‘0‘+1) : second; 24 console.log(year+‘-‘+month+‘-‘+day+week+‘/‘+hour+‘:‘+minute+‘:‘+second+‘/‘+time+‘/‘+timer+‘/‘+times);
以上是关于获取当地时间的主要内容,如果未能解决你的问题,请参考以下文章