【问题标题】:Format a PostgreSQL create_timestamp in React app在 React 应用程序中格式化 PostgreSQL create_timestamp
【发布时间】:2020-10-18 02:47:46
【问题描述】:

我在 React 应用程序中格式化 postgres create_timestamp 时遇到问题。我觉得它应该很容易,但我无法破解它。

我想转这个时间戳字符串:

2020-10-17T22:43:19.720Z

进入

October 17, 2020 at 5:23pm

我尝试过const createdAt = new Date('2020-10-17T22:43:19.720Z')——但结果是一个对象,所以我不确定如何获得最终的October 17, 2020 at 5:23pm 格式。

【问题讨论】:

    标签: javascript postgresql date timestamp


    【解决方案1】:

    create_timestamp = 2020-10-17T22:43:19.720Z;

      const createdAt = new Date(create_timestamp);
      const createdDate = createdAt.toLocaleDateString('en-US');
      const createdTime = createdAt.toLocaleTimeString('en-US');
    

    然后在渲染中:

    <div>{createdDate} at {createdTime}</div>
    

    【讨论】:

      猜你喜欢
      • 2019-09-20
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 2023-02-07
      相关资源
      最近更新 更多