如何在没有 'GMT+0000 (Coordinated Universal Time)' 的情况下获取 createdAt 时间戳?
How to get the the createdAt timestamp without 'GMT+0000 (Coordinated Universal Time)'?
我到处搜索这个,但没有找到正确的答案。我只想设置没有CUT时间
{name: "Registered:", value: `${user.createdAt}`},
{name: "Joined:", value: `${message.guild.joinedAt}`}
目前显示如下:
click here to see.
有什么办法可以去掉吗?
是的,可以删除它
{name: "Registered:", value: `${user.createdAt.toDateString()}`},
{name: "Joined:", value: `${message.guild.joinedAt.toDateString()}`}
您应该添加 toDateString()
以避免 GMT 或 CUT 时间
假设属性是 JS Date 实例,您可以使用以下函数之一来完成:
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);
我到处搜索这个,但没有找到正确的答案。我只想设置没有CUT时间
{name: "Registered:", value: `${user.createdAt}`},
{name: "Joined:", value: `${message.guild.joinedAt}`}
目前显示如下: click here to see.
有什么办法可以去掉吗?
是的,可以删除它
{name: "Registered:", value: `${user.createdAt.toDateString()}`},
{name: "Joined:", value: `${message.guild.joinedAt.toDateString()}`}
您应该添加 toDateString()
以避免 GMT 或 CUT 时间
假设属性是 JS Date 实例,您可以使用以下函数之一来完成:
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);