JS的時間格式化和時間戳轉換函式

2022-07-22 04:18:06 字數 1465 閱讀 3532

js的時間格式化和時間戳轉換函式

//

格式化時間

function

dateformat(fmt,date);

if(/(y+)/.test(fmt))

fmt=fmt.replace(regexp.$1, (date.getfullyear()+"").substr(4 - regexp.$1.length));

for(var k in

o)

if(new regexp("("+ k +")").test(fmt))

fmt = fmt.replace(regexp.$1, (regexp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+o[k]).length)));

return

fmt;}//

格式化標準時間、獲取當前時間

function

formatdate(flat,strtime)

else

da[0] =d.getfullyear();

da[1] = (d.getmonth()+1)<10?'0'+(d.getmonth() + 1):(d.getmonth() + 1);

da[2] = d.getdate()<10?'0'+d.getdate():d.getdate();

dt[0] = d.gethours()<10?'0'+d.gethours():d.gethours();

dt[1] = d.getminutes()<10?'0'+d.getminutes():d.getminutes();

dt[2] = d.getseconds()<10?'0'+d.getseconds():d.getseconds();

if(flat==0)

else}//

標準時間轉時間戳、獲取當前時間戳

function

tounix(flat,strtime)

else

o[0] = math.round(d.gettime()/1000);

o[1] = parseint(d.gettime() / 1000);

o[2] =(d).valueof();

o[3] =d.gettime();

o[4] =number(d);

o.push(1577808000); //

2020-01-01 00:00:00

return

o[flat];}//

時間戳轉標準時間、獲取當前時間戳

function

todate(tm)).replace(/年|月/g, "-").replace(/\//g, "-").replace(/日/g, " ").replace(/上午/g, "").replace(/下午/g, "").replace(/晚上/g, "");

return

d;}

時間戳格式化

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...

js 中時間戳轉換格式化日期

script src js jquery.js script script extend 日期 轉換為 unix 時間戳 param 2014 01 01 20 20 20 日期格式 return unix 時間戳 秒 datetounix function string 時間戳轉換日期 param...