Trước tiên hãy lấy ngày hiện tại -
var currentDate = new Date();
console.log("The current date is as follows="+currentDate); Bây giờ, chúng ta hãy loại bỏ giây / mili giây bằng cách đặt chúng thành 0 bằng setSeconds () -
currentDate.setSeconds(0,0);
Chuyển đổi sang Chuỗi ISO bằng toISOString () -
currentDate.toISOString()
Bây giờ chúng ta hãy xem mã hoàn chỉnh với đầu ra -
Ví dụ
var currentDate = new Date();
console.log("The current date is as follows="+currentDate);
currentDate.setSeconds(0,0);
console.log("After removing seconds from date, the new date is as
follows=");
console.log(currentDate.toISOString()); Để chạy chương trình trên, bạn cần sử dụng lệnh sau -
node fileName.js.
Đây, tên tệp của tôi là demo143.js.
Đầu ra
Điều này sẽ tạo ra kết quả sau -
PS C:\Users\Amit\JavaScript-code> node demo143.js The current date is as follows=Sat Aug 01 2020 18:20:09 GMT+0530 (India Standard Time) After removing seconds from date, the new date is as follows= 2020-08-01T12:50:00.000Z