
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Remove Seconds/ Milliseconds from Date and convert to ISO String?
Let’s get the current date first −
var currentDate = new Date(); console.log("The current date is as follows="+currentDate);
Now, let us remove seconds/ milliseconds by setting them to 0 using setSeconds() −
currentDate.setSeconds(0,0);
Convert to ISO String using toISOString() −
currentDate.toISOString()
Let us now see the complete code with output −
Example
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());
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo143.js.
Output
This will produce the following output −
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
- Related Articles
- How to convert ISO 8601 string to Date/time object in Android?
- Java Program to convert Date into milliseconds
- How to convert ISO 8601 String to Date/Time object in Android using Kotlin?
- Program to convert Milliseconds to Date Format in Java
- How to convert milliseconds to date format in Android?
- How to get min, seconds and milliseconds from datetime.now() in Python?
- How to convert milliseconds to date format in Android using Kotlin?
- Remove seconds from MySQL Datetime?
- How to convert from string to date data type in MongoDB?
- MongoDB – Fix “Failed to convert from type String to type Date”?
- Java Program to display date and time in Milliseconds
- Convert String to Date in Java
- How to convert JavaScript seconds to minutes and seconds?
- Java Program to Convert String to Date
- How do I get an ISO 8601 date in string format in Python?

Advertisements