JS 時間戳轉日期格式

2022-07-19 04:33:13 字數 495 閱讀 7733

1、日期轉換為時間戳,(如果日期格式為時間戳,將其轉為日期型別,否則輸出傳入的資料)

// 如果時間格式為時間戳,將其轉為日期

function timestamptodate(timestamp)

var date = new date(timestamp);

y = date.getfullyear();

m = (date.getmonth() + 1 < 10 ? '0'+(date.getmonth() + 1) : date.getmonth() + 1);

d = date.getdate();

return y+"-"+m+"-"+d;

} return timestamp;

}

2、時間戳轉換為日期

日期轉換為時間戳

時間戳轉日期格式

時間戳轉日期格式 轉換前格式 時間戳 秒 時間戳 毫秒 轉換後格式 年月日時分秒 年月日 時分秒 月日時 轉換前 例 1555459200 1555459200000 轉換後 例 2019 04 17 08 00 00 2019 04 17 08 00 00 格式 yyyy mm dd hh mm ...

js時間戳轉日期

方式一 方式一 var date new date parseint timestart 1000 tolocalestring replace d 最後得到的是2019 8 4 上午9 29 格式的資料 方式二 function add0 m function format shijianchuo...

PHP日期格式轉時間戳

php 提供了函式可以方便的將各種形式的日期轉換為時間戳,該類函式主要是 strtotime 將任何英文文字的日期時間描述解析為時間戳。mktime 從日期取得時間戳。strtotime strtotime 函式用於將英文文字字串表示的日期轉換為時間戳,為 date 的反函式,成功返回時間戳,否則返...