另一个var中的setDate方法返回不同的值 [英] setDate method within another var returning a different value

查看:73
本文介绍了另一个var中的setDate方法返回不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些为什么不一样?

var now = new Date();
now.setDate(3);
console.log(now) //returns formatted date depending on current date

And。 ..

var now = new Date();
var day = now.setDate(3);
console.log(day) //returns just numbers

??!

JSFiddle

推荐答案

因为setDate返回它应该的内容,所以从纪元开始的毫秒数

Because setDate returns what it's supposed to, which is the number of milliseconds from epoch.


返回值:一个数字,表示介于之间的毫秒数
日期对象和1970年1月1日午夜

Return Value: A Number, representing the number of milliseconds between the date object and midnight January 1 1970

这篇关于另一个var中的setDate方法返回不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆