快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

js中newDate()怎么用-创新互联

这篇文章主要介绍了js中new Date()怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

为平山等地区用户提供了全套网页设计制作服务,及平山网站建设行业解决方案。主营业务为成都做网站、成都网站制作、平山网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

js new Date() 测试

var t = new Date().toString(); //t = "Thu Oct 31 2019 11:36:57 GMT+0800 (中国标准时间)"
 var t1 = new Date();
 var data_arry =[];
 var that = new Date();
 data_arry.push(that.constructor()); // Thu Oct 31 2019 11:50:26 GMT+0800 (中国标准时间)"
data_arry.push(that.getDate()); //31
data_arry.push(that.getDay()); // 4
data_arry.push(that.getFullYear()); //2019
data_arry.push(that.getHours()); // 11
data_arry.push(that.getMilliseconds()); // 401
data_arry.push(that.getMinutes()); // 50
data_arry.push(that.getMonth()); //9
data_arry.push(that.getSeconds()); //26
data_arry.push(that.getTime()); //1572493826401
data_arry.push(that.getTimezoneOffset()); //-480
data_arry.push(that.getUTCDate()); //31
data_arry.push(that.getUTCDay());
data_arry.push(that.getUTCFullYear());
data_arry.push(that.getUTCHours());
data_arry.push(that.getUTCMilliseconds());
data_arry.push(that.getUTCMinutes());
data_arry.push(that.getUTCMonth());
data_arry.push(that.getUTCSeconds());
data_arry.push(that.getYear());
data_arry.push(that.setDate());
data_arry.push(that.setFullYear());
data_arry.push(that.setHours());
data_arry.push(that.setMilliseconds());
data_arry.push(that.setMinutes());
data_arry.push(that.setMonth());
data_arry.push(that.setSeconds());
data_arry.push(that.setTime());
data_arry.push(that.setUTCDate());
data_arry.push(that.setUTCFullYear());
data_arry.push(that.setUTCHours());
data_arry.push(that.setUTCMilliseconds());
data_arry.push(that.setUTCMinutes());
data_arry.push(that.setUTCMonth());
data_arry.push(that.setUTCSeconds());
data_arry.push(that.setYear());
data_arry.push(that.toDateString());
data_arry.push(that.toGMTString());
//data_arry.push(that.toISOString()); 报错
data_arry.push(that.toJSON());
data_arry.push(that.toLocaleDateString());
data_arry.push(that.toLocaleString());
data_arry.push(that.toLocaleTimeString());
data_arry.push(that.toString());
data_arry.push(that.toTimeString());
data_arry.push(that.toUTCString());
data_arry.push(that.valueOf());

函数

 function get_nowtime() {
      var date = new Date();
      return (date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate());
    }
    console.log(get_nowtime());

扩展阅读:

JS获取当前时间戳的方法-JavaScript 获取当前时间戳

JavaScript 获取当前时间戳:

第一种方法:

var timestamp =Date.parse(new Date());

结果:1280977330000

第二种方法:

var timestamp =(new Date()).valueOf();

结果:1280977330748

第三种方法:

var timestamp=new Date().getTime();

结果:1280977330748

第一种:获取的时间戳是把毫秒改成000显示,

第二种和第三种是获取了当前毫秒的时间戳。

我和同事在用js实现一个显示出分析数据所剩大概时间的过程中,时间总是变给0,结果很怪异,最后发现获取时间的时候用的是Date.parse(newDate())获取的时间戳把毫秒改成了000显示,所以时间差计算的不准确。

可以用第二种或第三种方法计算时间差。

js中单独调用new Date(),例如document.write(new Date());

显示的结果是:Mar 31 10:10:43 UTC+0800 2012 这种格式的时间

但是用new Date() 参与计算会自动转换为从1970.1.1开始的毫秒数

感谢你能够认真阅读完这篇文章,希望小编分享的“js中new Date()怎么用”这篇文章对大家有帮助,同时也希望大家多多支持创新互联成都网站设计公司,关注创新互联成都网站设计公司行业资讯频道,更多相关知识等着你来学习!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、网站设计器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页标题:js中newDate()怎么用-创新互联
网页链接:http://6mz.cn/article/cojgid.html

其他资讯