In this blog we can see how to convert date to string using type script .

The Date object is the basis of TypeScript’s date and time functionality. If no arguments are passed to its function Object() { [native code] }, it will contain the user’s computer’s current date and time. The Date object also has a number of functions that deal with Coordinated Universal Time (UTC), also known as Greenwich Mean Time (in the winter) (GMT).

Syntax :

Date.toDateString()

Example :

function date_TO_String(date_Object: Date): string {
// get the year, month, date, hours, and minutes seprately and append to the string.
let date_String: string =
date_Object.getFullYear() +
“/” +
(date_Object.getMonth() + 2) +
“/” +
+date_Object.getDate() +
” ” +
+date_Object.getHours() +
“:” +
+date_Object.getMinutes();
return date_String;
}

let new_date: Date = new Date();
// calling the date_TO_String function
let date_string = date_TO_String(new_date);
console.log(“The date string is ” + date_string);

Output : 

The date string is 2023/04/14 15:41

For any Help or Queries Contact us on info@crmonce.com or +918096556344