js怎样把日期和时间时间戳 Timestamp格式化

 时间:2024-10-12 14:18:21

1、最简单获取时间戳的方式是var t坡纠课柩ime = +new Date;console.log(time)然后格式化Dat髫潋啜缅e.prototype.datetime = function() {returnmyDate.getFullYear() + '-' +('0' + (myDate.getMonth()+1)).slice(-2)+ '-' + myDate.getDate() + ' '+myDate.getHours()+ ':'+('0' + (myDate.getMinutes())).slice(-2)+ ':'+myDate.getSeconds(); };1523635561616可以替换成timevar myDate = new Date(1523635561616);myDate.datetime();将输出2018-04-14 00:06:01

js怎样把日期和时间时间戳 Timestamp格式化

2、还可以使用moment.js(下载地址 http://momentjs.com/)直接调用format格式化即可。var date = new Date();var formattedDate = moment(date).format('YYYYMMDD');

js怎样把日期和时间时间戳 Timestamp格式化

3、把一个日期对象转换为可读字符串var ts = new Date();console.log(ts.toDateString())# Fri Apr 13 2018

js怎样把日期和时间时间戳 Timestamp格式化

4、返回ISO标准的日期var ts = new Date();console.log(ts.toISOString());# 2018-04-13T11:42:30.244Z

js怎样把日期和时间时间戳 Timestamp格式化

5、toJSON 返回json形式的日期var ts = new Date();console.log(ts.toJSON());# 2018-04-13T11:42:30.244Z

js怎样把日期和时间时间戳 Timestamp格式化

6、toLocaleDateString 返回本地区域日期var ts = new Date();console.log(ts.toLocaleDateString());# 2018/4/13

js怎样把日期和时间时间戳 Timestamp格式化

7、toLocaleTimeString 返回本地区域时间var ts = new Date();console.log(ts.toLocaleTimeString());# 下午7:42:30

js怎样把日期和时间时间戳 Timestamp格式化

8、toLocaleString 把本地区域日期转换为字符串var ts = new Date();console.log(ts.toLocaleString());# 2018/4/13 下午7:42:30

js怎样把日期和时间时间戳 Timestamp格式化

9、toString 把日期转换为字符串var ts = new Date();console.log(ts.toString());# Fri Apr 13 2018 19:42:30 GMT+0800 (中国标准时间)

js怎样把日期和时间时间戳 Timestamp格式化

10、toTimeString 把时间部分转换为字符串var ts = new Date();console.log(ts.toTimeString());# 19:42:30 GMT+0800 (中国标准时间)

js怎样把日期和时间时间戳 Timestamp格式化

11、toUTCString() 根据通用时间将 Date 对象转换为字符串var ts = new Date();console.log(ts.toUTCString());# Fri, 13 Apr 2018 11:42:30 GMT

js怎样把日期和时间时间戳 Timestamp格式化
  • 无烬星河攻略
  • 2021QQ在哪里添加腾讯课堂小图标?
  • 小恩爱APP怎么绑定QQ号
  • 最新版王者荣耀怎么玩专精装备?
  • 庆余年2小说解说视频怎么看?
  • 热门搜索
    国庆小报手抄报 保护环境手抄报大全 敬廉崇洁手抄报内容 手抄报插图简单又漂亮 防灾减灾一等奖手抄报 关于读书的手抄报资料 科技手抄报大全 中秋节手抄报大全 弟子规手抄报图片 手抄报a4版面设计图