onLoad: function(options) { //获取当前时间戳 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(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()); console.log("当前时间:" + Y + M + D + h + ":" + m + ":" + s); },
微信小程序获取当前时间戳
未经允许不得转载:小叶白龙博客 » 微信小程序获取当前时间戳
评论前必须登录!
注册