I'm receiving date and time from the REST API in the below format
2016-01-17T:08:44:29+0100
I want to format this date and time stamp like
17-01-2016 08:44:29
It should be dd/mm/yyyy hh:mm:ss
How to format this in TypeScript?
You can format date/time in TypeScript, by using any of the built-in methods on the Date object or creating a reusable function that formats the date according to your requirements by leveraging built-in methods like getFullYear , getMonth , etc.
Use the Date type to type a Date object in TypeScript, e.g. const date: Date = new Date() . The Date() constructor returns an object that has a type of Date . The interface defines typings for all of the built-in methods on the Date object.
you can use moment.js. install moment js in your project
moment("2016-01-17T:08:44:29+0100").format('MM/DD/YYYY');
for more format option check Moment.format()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With