時間戳
有兩種方式獲得:
var myDate=new Date()
myDate.getYear();
//獲取當前年份(2位)
myDate.getFullYear();
//獲取完整的年份(4位,1970-???)
myDate.getMonth();
//獲取當前月份(0-11,0代表1月)
myDate.getDate();
//獲取當前日(1-31)
myDate.getDay();
//獲取當前星期X(0-6,0代表星期天)
myDate.getTime();
//獲取當前時間(從1970.1.1開始的毫秒數)
myDate.getHours();
//獲取當前小時數(0-23)
myDate.getMinutes();
//獲取當前分鐘數(0-59)
myDate.getSeconds();
//獲取當前秒數(0-59)
myDate.getMilliseconds();
//獲取當前毫秒數(0-999)
myDate.toLocaleString( );
//獲取日期與時間
utli
首先,在要獲取時間的.js文件中request 進util.js文件
然後:
onLoad: function (options) {
var that=this;
var Time=util.formatTime(new Date());//取得當前年月日小時時間
var ass=new Date(that.data.trytime).getTime();
}
數組賦值
我要傳入三個結束時間,拿到它們的時間戳,並把時間戳存在data一個數組裏
Page({
data:{
flashTime:["2019/9/24/17:21","2019/9/24/17:58"],
endTime:[],//放時間戳
current_time:''//放當前時間戳
},
onLoad:function(options){
var that=this;
let endTime=that.data.endTime;
var myDate=new Date().getTime();//到當前時間的時間戳
for (let i = 0; i <= 1; i++) {
let endtime=new Date(that.data.flashTime[i]).getTime();
endTime.push(endtime);
//數組存參的關鍵,push進去
that.setData({
current_time:myDate,
endTime:endTime
})
}
}
})
這樣就能在頁面拿到endTime了。