-2

I want to convert from timestamp to required date format

Timestamp:- 2023-06-12T00:00:00

I want to convert to this format:- 12-Jun-2023 (DD-MMM-YYYY)

Suggest me how to achieve this

mplungjan
  • 169,008
  • 28
  • 173
  • 236
ashok
  • 199
  • 1
  • 12
  • 1. No need for jQuery, JavaScript does this without jQuery at all. 2. Please ***[search your question before asking](https://www.google.com/search?q=javascript+format+date+DD-MMM-YYYY+site%3Astackoverflow.com)*** – mplungjan Jun 12 '23 at 18:06
  • 1
    `const timestamp = '2023-06-12T00:00:00'; const date = new Date(timestamp); const options = { day: 'numeric', month: 'short', year: 'numeric' }; const formattedDate = date.toLocaleDateString('en-GB', options).replace(/ /g, '-'); console.log(formattedDate);` – mplungjan Jun 12 '23 at 18:12

1 Answers1

-1

var timeStamp = "2023-06-12T00:00:00";

const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

var date = new Date(timeStamp);

var formattedDate = date.getDate() + "-" + monthNames[date.getMonth() - 1] + "-" + date.getFullYear();

console.log(formattedDate);
Nikhil Parmar
  • 783
  • 6
  • 10