微信小程式獲取當前時間戳 獲取當前時間 時間戳加減

2022-06-11 13:42:08 字數 2077 閱讀 8258

//

獲取當前時間戳

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();

微信小程式獲取當前時間戳 獲取當前時間 時間戳加減

獲取當前時間戳 var timestamp date.parse new date timestamp timestamp 1000 console.log 當前時間戳為 timestamp 獲取當前時間 var n timestamp 1000 var date new date n 年 var ...

微信小程式獲取當前時間戳 獲取當前時間 時間戳加減

pi network 免費挖礦國外熱門專案 乙個 幣大約值3元到10元 相信過去btc的人,信不信未來的pi,了解一下,唯一乙個高度與之持平的專案 獲取當前時間戳 var timestamp date.parse new date timestamp timestamp 1000 console.l...

微信小程式獲取當前時間及獲取當前日期

首先,在要獲取時間的.js檔案中載入util.js檔案 var util require utils util.js 然後在onload方法中,呼叫util.js中的formattime方法獲取當前時間 var timenow util.formattime new date this.setdat...