将日期随时间转换为小时/下午格式

发布于 2025-01-24 19:10:21 字数 276 浏览 5 评论 0原文

想要掩盖thu Apr 28 2022 07:00:00 GMT+0530到晚上7点 UI就是这样,

“在此处输入图像描述”

也想掩盖7pm至4月28日至4月28日2022 07:00:00格式

Want to covert Thu Apr 28 2022 07:00:00 GMT+0530 into 7pm
UI is like this,

enter image description here

also want to covert that 7pm to Thu Apr 28 2022 07:00:00 format

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨敛清荷 2025-01-31 19:10:21

如果为您工作,请尝试一下

    var time = new Date('Thu Apr 28 2022 19:00:00 GMT+0530');
    console.log(
        time.toLocaleString('en-US', { hour: 'numeric', hour12: true })
    );

Try this, if it is working for you

    var time = new Date('Thu Apr 28 2022 19:00:00 GMT+0530');
    console.log(
        time.toLocaleString('en-US', { hour: 'numeric', hour12: true })
    );
习ぎ惯性依靠 2025-01-31 19:10:21

您可以像这样格式化日期:

<TimePicker
    showMinute={false}
    showSecond={false}
    use12Hours
    onChange={(val, data) => {
        // Thu Apr 28 2022 07:00:00 format
        console.log(val?.format('ddd, MMMM D YYYY, h:mm:ss'));
    }}
/>

您可以在“时刻文档”中阅读有关格式化的更多信息。

You can format your date like this:

<TimePicker
    showMinute={false}
    showSecond={false}
    use12Hours
    onChange={(val, data) => {
        // Thu Apr 28 2022 07:00:00 format
        console.log(val?.format('ddd, MMMM D YYYY, h:mm:ss'));
    }}
/>

You can read more about formatting in moment documentation. Moment Format

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文