Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format datetime in TypeScript

Tags:

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?

like image 993
Protagonist Avatar asked Jan 15 '17 08:01

Protagonist


People also ask

How do I change the Date format 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.

Is there dateTime type in TypeScript?

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.


1 Answers

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()

like image 197
Amit kumar Avatar answered Sep 23 '22 14:09

Amit kumar