如何在JavaScript中合并两个日期? [英] How to merge two dates in JavaScript?
本文介绍了如何在JavaScript中合并两个日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
date.toString ()= Wed Dec 21 2011 00:00:00 GMT + 0000(GMT)
time.toString()= Sun Dec 31 2000 03:00:00 GMT + 0000(GMT)
#我想要结束
datetime.toString()= Wed Dec 21 2011 03:00:00 GMT + 0000(GMT)
如何最好地完成这个?
解决方案
var datetime = new Date(date.getFullYear(),date.getMonth(),date.getDate(),
time.getHours(),time.getMinutes(),time.getSeconds());
I have 2 date objects. I want to take the date from one and the time from the other and combine them into a new date object.
date.toString() = Wed Dec 21 2011 00:00:00 GMT+0000 (GMT)
time.toString() = Sun Dec 31 2000 03:00:00 GMT+0000 (GMT)
# I want to end up with
datetime.toString() = Wed Dec 21 2011 03:00:00 GMT+0000 (GMT)
How can I best accomplish this?
解决方案
var datetime = new Date(date.getFullYear(), date.getMonth(), date.getDate(),
time.getHours(), time.getMinutes(), time.getSeconds());
这篇关于如何在JavaScript中合并两个日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文