简体   繁体   中英

JavaScript Date Manipulation (Insert Current Time in old Date)

I want to ask a question. Can we insert current Time in old Date?

Like this is a old date "Fri Nov 19 2021 00:00:00 GMT+0500 (Pakistan Standard Time)" and I want to convert it to something like this "Fri Nov 19 2021 (current Time right now) GMT+0500 (Pakistan Standard Time)". Thanks in advance.

You can try using the setTime method, as in the following example:

const saveTime = new Date();
console.log(saveTime);
Tue Nov 23 2021 06:24:29 GMT-0500 (Cuba Standard Time)
saveTime.setTime(new Date().getTime());
console.log(saveTime);
Tue Nov 23 2021 06:24:43 GMT-0500 (Cuba Standard Time)

use setTime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM