I have searched everywhere for this but I haven't got the right answer. I just want to set it without the CUT time.
{name: "Registered:", value: `${user.createdAt}`},
{name: "Joined:", value: `${message.guild.joinedAt}`}
It currently shows up like this: click here to see.
Is there any way to remove it?
CodePudding user response:
Assuming the properties are JS Date instances, you can use one of these functions to do it:
function formatDateV1 (date) {
return date.toLocaleString(undefined, {dateStyle: 'medium', timeStyle: 'medium', hour12: false});
}
function formatDateV2 (date) {
return `${date.toDateString()} ${date.toTimeString().slice(0, 8)}`;
}
const date = new Date();
const user = {createdAt: date};
const message = {guild: {joinedAt: date}};
const registerV1 = {name: "Registered:", value: formatDateV1(user.createdAt)};
console.log('registerV1', registerV1);
const joinV1 = {name: "Joined:", value: formatDateV1(message.guild.joinedAt)};
console.log('joinV1', joinV1);
const registerV2 = {name: "Registered:", value: formatDateV2(user.createdAt)}
console.log('registerV2', registerV2);
const joinV2 = {name: "Joined:", value: formatDateV2(message.guild.joinedAt)}
console.log('joinV2', joinV2);
CodePudding user response:
Yes it's possible to remove it
{name: "Registered:", value: `${user.createdAt.toDateString()}`},
{name: "Joined:", value: `${message.guild.joinedAt.toDateString()}`}
You should to add toDateString()
to avoid the GMT or CUT time