当前位置: 代码迷 >> JavaScript >> momentjs-更改当地时间的格式
  详细解决方案

momentjs-更改当地时间的格式

热度:36   发布时间:2023-06-05 09:35:57.0

我正在利用时间来获取时间。 我正在用以下格式获取它:2019年2月21日星期四10:44:21 GMT + 0500(巴基斯坦标准时间) 但是,我需要03:44:21 PM格式。 谁能告诉我如何使用momentjs做到这一点?

您可以为此目的使用momentjs moment().format()

moment().format('hh:mm:ss A')

有关更多详细信息,请访问

本地也可以用于转换出固定偏移模式:

moment.parseZone('2016-05-03T22:15:01+02:00').local().format('hh:mm:ss A');

获取您的TimeZone并使用以下方法转换时区:

let timeZone = moment.tz.guess();
let date = 'Thu Feb 21 2019 10:44:21 GMT+0500' // input date (other timezone)
let convertDate = moment(date).tz(timeZone) //converted Time
  相关解决方案