時間戳轉格式化的時間

2021-08-11 11:45:36 字數 603 閱讀 8638

第一步:將時間戳轉化成時間物件。

var timestampobj = new

date(timestamp)

第二步:呼叫函式

changetime(timestampobj)

//傳入時間物件

function

changetime (time)

另外一種方法:(網上找的)

var timestamp4 = new

date(1511892000000)

var re = timestamp4.tolocaledatestring().replace(/\//g, "-") + " " + timestamp4.totimestring().substr(0, 8)

console.dir(re)

script>

re就是格式化後的時間,但是tolocaledatestring()有相容性問題,不同的瀏覽器表現不一樣,例如搜狗瀏覽器最後展示成這個樣子wed nov 29 2017 02:00:00,使用要謹慎!

時間戳轉格式化時間和時間轉時間戳

時間戳轉格式化時間 param params 13位時間戳 return type yyyy mm dd yyyy mm dd hh mm ss yyyy mm dd yyyy mm dd hh mm ss export const timestampfromat params,type 舉例par...

時間戳格式化

1.格式化為yyyy mm dd hh mm ss形式的 public static string formatdatetime date date 2.格式化為 年 月 日 形式 public static string formatdate date mydate public static i...

時間戳格式化

獲取系統當前時間戳 long timestamp system.currenttimemillis 將時間戳轉化為date物件 date date new date timestamp 按指定格式生成解析物件 dateformat dateformat new dateformat yyyy年 mm...