微信小程序时间转换成时间戳、获取当前时间戳、获取当前时间、时间戳加减
生活随笔
收集整理的這篇文章主要介紹了
微信小程序时间转换成时间戳、获取当前时间戳、获取当前时间、时间戳加减
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
時間轉換成時間戳
var sTime = "2020-10-22 10:22:22"; var timestamp = Date.parse(new Date(sTime )); //獲取當前時間戳 var timestamp = Date.parse(new Date()); timestamp = timestamp / 1000; console.log("當前時間戳為:" + timestamp); //獲取當前時間 var n = timestamp * 1000; var date = new Date(n); //年 var Y = date.getFullYear(); //月 var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1); //日 var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); //時 var h = date.getHours(); //分 var m = date.getMinutes(); //秒 var s = date.getSeconds(); console.log("當前時間:" +Y+M+D+h+":"+m+":"+s); //轉換為時間格式字符串 console.log(date.toDateString()); console.log(date.toGMTString()); console.log(date.toISOString()); console.log(date.toJSON()); console.log(date.toLocaleDateString()); console.log(date.toLocaleString()); console.log(date.toLocaleTimeString()); console.log(date.toString()); console.log(date.toTimeString()); console.log(date.toUTCString()); //時間、時間戳加減 以加一天舉例//加一天的時間戳: var tomorrow_timetamp = timestamp + 24 * 60 * 60; //加一天的時間: var n_to = tomorrow_timetamp * 1000; var tomorrow_date = new Date(n_to); //加一天后的年份 var Y_tomorrow = tomorrow_date.getFullYear(); //加一天后的月份 var M_tomorrow = (tomorrow_date.getMonth() + 1 < 10 ? '0' + (tomorrow_date.getMonth() + 1) : tomorrow_date.getMonth() + 1); //加一天后的日期 var D_tomorrow = tomorrow_date.getDate() < 10 ? '0' + tomorrow_date.getDate() : tomorrow_date.getDate(); //加一天后的時刻 var h_tomorrow = tomorrow_date.getHours(); //加一天后的分鐘 var m_tomorrow = tomorrow_date.getMinutes(); //加一天后的秒數 var s_tomorrow = tomorrow_date.getSeconds();轉自:https://blog.csdn.net/u011280778/article/details/92840364
總結
以上是生活随笔為你收集整理的微信小程序时间转换成时间戳、获取当前时间戳、获取当前时间、时间戳加减的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: .50重机枪打无人机能行吗?
- 下一篇: 微信小程序页面文字超出一行隐藏,文字超出