将时间戳转换为 ("MMM DD, HH:mm") 格式。JS

use*_*234 6 javascript date

我有一个日期作为服务器响应的时间戳返回,我想("MMM DD, HH:mm")使用toUTCString(). 到目前为止,我有这个:

date = new Date(1555649122787).toUTCString()
Run Code Online (Sandbox Code Playgroud)

o/p: "Mon, 22 Apr 2019 23:00:32 GMT",但是我想要这种格式的 o/p:

Apr 22, 23:00. 不幸的是,对于我的项目,我无法使用 moment.js 作为库。还有其他更好的方法吗?

Mis*_*ojo 4

Marco 回答 Intl.DateTimeFormat 是最好的方法,但他忘记提及我们可以删除我们不想要的日期元素

dateC = new Date(1555649122787);

B_Options = {
  month: 'short', day: 'numeric',
  hour: '2-digit', minute: '2-digit',
  hour12: false,
  timeZone: 'America/Los_Angeles' 
};

console.log(new Intl.DateTimeFormat('en-US', B_Options).format(dateC) );
Run Code Online (Sandbox Code Playgroud)