js時間戳轉為日期格式的方法

2021-07-31 15:26:29 字數 2150 閱讀 2674

一、js把時間戳轉為為普通日期格式

function

add0

(m) function

format

(shijianchuo)

format 格式

* @param timestamp 要格式化的時間 預設為當前時間

* @return 格式化的時間字串

*/function

date

(format, timestamp) else

}; var txt_weekdays = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];

var txt_ordin = ;

var txt_months = ["", "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];

var f = ,

d: function

(),

j: function

(),

l: function

(),

n: function

(),

s: function

(),

w: function

(),

z: function

(),

// week

w: function

() else else

} },

// month

f: function

(),

m: function

(),

m: function

(),

n: function

(),

t: function

() else else

} },

// year

l: function

(),

//o not supported yet

y: function

(),

y: function

(),

// time

a: function

(),

a: function

(),

b: function

(),

g: function

(),

g: function

(),

h: function

(),

h: function

(),

i: function

(),

s: function

(),

//u not supported yet

// timezone

//e not supported yet

//i not supported yet

o: function

(),

p: function

(),

//t not supported yet

//z not supported yet

// full date/time

c: function

(),

//r not supported yet

u: function

() };

return format.replace(/[\]?([a-za-z])/g, function

(t, s) else

if( f[s] ) else

return ret;

});

}

date('y-m-d','1350052653');//很方便的將時間戳轉換成了2012-10-11 

date('y-m-d h:i:s','1350052653');//得到的結果是2012-10-12 22:37:33

js時間戳轉為日期格式

這個在php mssql 日期型別為datetime ajax的時候才能用到,js需要把時間戳轉為為普通格式,一般的情況下可能用不到 彈出 2010年12月23日 10 53 也可以用 如果想彈出 2010 10 20 10 00 00這個格式的也好辦 另外我也參考了別的網站的一些東東,如下 fun...

js時間戳轉為日期格式

這個在php mssql 日期型別為datetime ajax的時候才能用到,js需要把時間戳轉為為普通格式,一般的情況下可能用不到 彈出 2010年12月23日 10 53 也可以用 如果想彈出 2010 10 20 10 00 00這個格式的也好辦 view plain cop另外我也參考了別的...

js時間戳轉為日期格式

1.js將時間轉換成時間戳 var times1 date.parse new date var times2 new date valueof var times3 new date gettime 2.js獲取制定時間戳的方法 var oldtime new date 2015 06 23 08...