JavaScript和Python时间戳转换

JavaScript和Python时间戳转换



Python 返回的时间戳以浮点形式返回秒


Javascript返回的时间戳返回的是毫秒


如果要让Python和Javascript时间戳等价则需

int(time.time()*1000)

附JS时间转换:


JS返回date对象的日期部分的本地化字符串 :

new Date().toLocaleDateString()

JS返回date对象的时间部分的本地化字符串

new Date().toLocaleTimeString()

JS接收后端时间戳转为JS时间

new Date(parseInt("后端返回的时间戳"))

PS:
Date对象构造函数参数说名month是返回 0-11 ,因此获取月份需要加一

let now_date = new Date()
let now_date_format = `${
      
      now_date .getFullYear()}/${
      
      now_date .getMonth()+1}/${
      
      now_date .getDate()}`

猜你喜欢

转载自blog.csdn.net/qq_44718932/article/details/126301756
今日推荐