get 23/01 date in typescript

To get the date in the format of 23/01, you can use the toLocaleDateString() method of the Date object in JavaScript.

index.ts
const date = new Date();
const formattedDate = date.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit' });
console.log(formattedDate); // Output: 23/01
164 chars
4 lines

Alternatively, you can also use a library like moment.js to format the date.

index.ts
import moment from 'moment';

const date = new Date();
const formattedDate = moment(date).format('DD/MM');
console.log(formattedDate); // Output: 23/01
152 chars
6 lines

Both methods will give you the date in the desired format.

gistlibby LogSnag