How To Get ISO Date Without The Milliseconds Using JavaScript

Get ISO Date without the Milliseconds using JavaScript

This article will show you how to get ISO Date without the milliseconds using JavaScript. Here are some ways to do it with examples to make it easier for readers to understand. Let’s read this article now.

What is ISO Date?

Weekday, ordinal Date, and calendar day are the three fundamental categories.

A calendar date is represented by a 4-digit year number, a 2-digit month number, a 2-digit day number. For instance, August 2, 1953, could be expressed as follows:

19530802 or 1953/08/02

A four-digit year number is followed by a three-digit number representing the number of days in the year when writing an ordinal date. For instance, August 2, 1953, could be written as follows:

1953214 or 1953-214

A weekday is represented by a 4-digit year number, a W, a 2-digit week number, a 1-digit weekday number (1 = Monday, 2 = Tuesday,…, 7 = Sunday), and a 4-digit week number. For instance, August 2, 1953, could be written as follows:

1953W317 or 1953-W31-7

Note that you must always write all the digits. Therefore, year 47 must be written as 0047.

Get ISO Date without the milliseconds using JavaScript

Use the split() method

A string can be divided into an array of substrings using the split() method of a string object, which returns the new array.


split(separator, limit)


  • separator: Specifies the character or regular expression to divide the string or separator. The complete string is returned if it is omitted (An array with only one item).
  • limit: An integer indicating the number of splits; items that are included in the array after the division limit.

We can use this method to split the Date ISO string into the string we need to find and the string containing milliseconds to get the value at the discretion of the problem.


console.log(new Date().toISOString().split('.')[0]);



You can see that if we create a new Date() to get the current time, the second time will be separated from the millisecond by a “.” dot symbol. So we use the slice method to split the string at the dot symbol position and get the string with index equal to one, and then print it to the console.

Use the slice() method

The slice() method has the function of extracting part of a string. The method will return a new string, the quoted portion of the original string.

Use the start and end parameters to specify the part to be extracted from the original string. Note that the first position of the string is 0, followed by one, .etc


slice(start, end)


  • start: The starting position to extract.
  • end: The extraction end position. The extracted content will not include the character at the end position. If no end parameter is provided, the method will extract from the start position to the end of the string.


console.log(new Date().toISOString().slice(0, -5));



In this approach, we will rely on the Date() pattern. We can see that milliseconds in ISO will have four values, so we will use the slice method to cut the part we don’t want to get, which is the millisecond and print the string we need. Find the screen. The pulse return result is the same as above. I hope this is helpful to you.


To summarize, in this article, we went through several ways to get ISO Date without the milliseconds using JavaScript. You can do it by using the split() method or slice() method. Let’s try two ways. Good luck for you!

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *