如果日期爲2015年04月29日或者2015-04-29格式時。js是不認識‘年、月、日’和’-‘的。所以要先把符號轉爲"/"
var str = "2015年04月29日"; str = str.replace(/年/g,'/'); str = str.replace(/月/g,'/'); str = str.replace(/日/g,''); var date = new Date(str); content=date.getTime(); alert(content); //結果爲時間戳
如果日期爲2015年04月29日或者2015-04-29格式時。js是不認識‘年、月、日’和’-‘的。所以要先把符號轉爲"/"
var str = "2015年04月29日"; str = str.replace(/年/g,'/'); str = str.replace(/月/g,'/'); str = str.replace(/日/g,''); var date = new Date(str); content=date.getTime(); alert(content); //結果爲時間戳