Hi Friends 👋,

Welcome to Infinitbility ❤️!

This tutorial will help you to convert date to iso format in typescript, here we will use the toISOString() method to convert date to iso format.

what is toISOString()?

The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset, as denoted by the suffix “Z”.

– MDN

Let’s start today’s tutorial How to convert date to iso format in typescript?

Before diving into code, let’s see what we are going to do.

  1. Create a date and store it in a variable.
  2. use toISOString() method
  3. check converted date output
const date = new Date('05 October 2011 14:48 UTC');
console.log(date.toISOString());
// expected output: 2011-10-05T14:48:00.000Z

When you run the above code, you will get an iso date format example output.

For now, let’s check the output.

Output

TypeScript, convert date to iso string example
TypeScript, convert date to iso string example

All the best 👍.