close

How do you format a Date/Time in TypeScript?

Today We are Going To Solve This in Javascript. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

How do you format a Date/Time in TypeScript?

  1. format a Date/Time in TypeScript

    To format a Date/Time in TypeScript just Use moment js. You can use moment js in your project. Just install it with the below command: moment("2021-03-17T:02:34:29+0100").format('MM/DD/YYYY');

  2. How do you format a Date/Time in TypeScript?

    To format a Date/Time in TypeScript just Use the below code. Just use the below code to format a date or time in typescript. Just try it. var reTime = /(\d+\-\d+\-\d+)\D\:(\d+\:\d+\:\d+).+/; var originalTime = '2021-03-17T:02:34:29+0100'; var newTime = originalTime.replace(this.reTime, '$1 $2'); console.log('newTime:', newTime);

Solution 1 : Use moment js

You can use moment js in your project. Just install it with the below command:

 moment("2021-03-17T:02:34:29+0100").format('MM/DD/YYYY');

Solution 2 : Use the below code

Just use the below code to format a date or time in typescript. Just try it.

var reTime = /(\d+\-\d+\-\d+)\D\:(\d+\:\d+\:\d+).+/;
var originalTime = '2021-03-17T:02:34:29+0100';
var newTime = originalTime.replace(this.reTime, '$1 $2');
console.log('newTime:', newTime);

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read These Solutions

Leave a Comment