+ 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?
5 Respostas
+ 1
const date = new Date();
console.log(date.toUTCString());
console.log(date.toGMTString());
+ 1
Will it work on any date as I have pick date from calander?
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
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()); ?
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();