Navigate back to the homepage

How to convert date to mm/dd/yyyy in typescript?

Infinitbility
TypeScript
April 27th, 2022 · 1 min read
keep affilitate

Hi Friends 👋,

Welcome to Infinitbility ❤️!

Today, we are going to learn How to convert date to mm/dd/yyyy in typescript?, here we will use custom method formatDate() method to convert date to mm/dd/yyyy format.

So, first we have to create a function which get date as a parameter and return formated like we want…

Here, we want format date as month/date/year like.

let’s dive in code…

1const formatDate = (date: Date) => {
2 function pad(s) { return (s < 10) ? '0' + s : s; }
3 var d = new Date(date)
4 return [pad(d.getMonth()+1), pad(d.getDate()), d.getFullYear()].join('/')
5}
6
7console.log(formatDate(new Date()))

Well, when you run above code, you can able to see date converted in mm/dd/yyyy format.

For now, let’s check the output.

Output

TypeScript, convert date to mm/dd/yyyy format example
TypeScript, convert date to mm/dd/yyyy format example

All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

melio affilitate

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to convert date to number in typescript?

TypeScript, convert date to number example.

April 27th, 2022 · 1 min read

How to convert date to epoch time in typescript?

TypeScript, convert date to epoch time example.

April 26th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:infi[email protected]