+ 1

Date format in Javascript

How to display date from api to client side in given format in react : sat, 26 sep 2022, 12:13:96 am?

27th Sep 2022, 2:18 PM
Dhruti
Dhruti - avatar
5 ответов
+ 1
const date = new Date(); console.log(date.toUTCString()); console.log(date.toGMTString());
27th Sep 2022, 2:59 PM
Jayakrishna 🇮🇳
+ 1
Will it work on any date as I have pick date from calander?
28th Sep 2022, 4:36 AM
Dhruti
Dhruti - avatar
0
That returns today's date.. You can create custom dates by : new Date(datestring) Ex: let date = new Date("2017-01-26"); new Date(year, month, date, hours, minutes, seconds, ms) Ex: let date = new Date(2000, 0, 1, 0, 0, 0, 0); // 1 Jan 2000, 00:00:00 let date = new Date(2023, 0, 1); // 2023, january, 1
28th Sep 2022, 9:02 AM
Jayakrishna 🇮🇳
0
But I need to fatch date from api data so I can not add like. Can I add that date veriable inside the method like (date1, date.toGMTString()); ?
30th Sep 2022, 6:55 AM
Dhruti
Dhruti - avatar
0
Sry i did not understand it. Not enough information to me.. If your API give you date then you can get into variable then use to what ever you want. You can pass if you have compatible method. Check it by trying.. Try const date = < get date from api > date.toGMTString();
30th Sep 2022, 11:22 AM
Jayakrishna 🇮🇳