Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 10位时间戳和13位时间戳
- * java的时间戳精度是毫秒,所以生成的是13位的
- * 而像c++或者php生成的时间戳默认就是10位的,其精度是秒
- */
- // 13位时间戳
- const timestamp13 = 1559712343273;
- // 方法一
- let date = new Date(timestamp13);
- console.log(date); // 2019-06-05T05:25:43.273Z
- // 方法二
- date = new Date();
- date.setTime(timestamp13);
- console.log(date); // 2019-06-05T05:25:43.273Z
- // day of the month
- console.log(date.getDate()); // 5
- // day of the week
- console.log(date.getDay()); // 3
- // get the year
- console.log(date.getFullYear()); // 2019
- // get the minutes of a date
- console.log(date.getUTCMinutes()); // 25
- // 10位时间戳
- const timestamp10 = 1560742200;
- // 先*1000,转换成毫米
- date = new Date(timestamp10 * 1000);
- console.log(date);
- // 转换成字符串 2019-06-17T03:30:00.000Z
- console.log(date.toISOString());
- // 使用moment也需要将精度转成毫秒
- const custom_time = moment(1560742200 * 1000).format("YYYY-MM-DD HH:mm:ss");
- console.log(custom_time);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement