简体   繁体   中英

How to convert one time format to another in javascript using moment.tz?

I have tried various methods but I'm unable to convert date like 1640638800 to 2022-11-27 16:00:00 America/New_York timezone format in javascript using moment.tz .

My current code was like

import * as moment from 'moment';
var date= new Date(0);
date.setUTCSeconds(1640638800);
moment.tz(date.getFullYear()+"-"+date.getMonth()+"-"+date.getDay() + " 10:00:00", "America/New_York");

Please help

const ts = 1640638800  
const m = moment.tz(ts, timezone)
const formatted = m.format('YYYY-MM-DD')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM