js如何把UTC格式的时间转换为任意指定时区的年月日时分秒

 

问题描述:

一个UTC时间:2017-09-15T16:00:00Z

指定一个时区,例如是:Asia/Yakutsk

如何转换为 年:月:日 时:分:秒 ?


 

第 1 个答案:

使用mement.js

//demo
var date = '2017-09-28T16:00:00Z';
var timezone = '"Asia/Shanghai';
moment(date).tz(timezone).format('YYYY-MM-DD hh:mm:ss');

如果是在微信小程序中使用,你需要先去moment官方下载moment-timezone-with-data.js这个文件到你的小程序应用中

const moment = require("./moment-timezone-with-data");
var date = '2017-09-28T16:00:00Z';
var timezone = '"Asia/Shanghai';
moment(date).tz(timezone).format('YYYY-MM-DD hh:mm:ss');

参考

moments.js http://momentjs.com/timezone/


 

第 2 个答案:

用第三方JS库, 比如 fecha 或者moment


我写了一个Dockerfile,它安装了crond服务添加一些环境变量到/root/.bash_profile# 添加一些环境变量到/root/.bash_p ...