[英]How to convert epoch timestamp to datetime with timezone in moment js?
How to convert epoch timestamp 1527140580
to Thu May 24 2018 11:13:00 GMT+0530 (India Standard Time)
in moment js ? 怎么把epoch timestamp 1527140580
转换成Thu May 24 2018 11:13:00 GMT+0530 (India Standard Time)
?
moment.unix(1527140580).format('DD/MM/YYYY HH:mm');
gives me 24/05/2018 11:13
给我24/05/2018 11:13
This is one way to do it 这是做到这一点的一种方法
console.log(moment.unix(1527140580).toString())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>
If the timezone at the end is important, you can read the timezone docs here to enable it in that string. 如果最后的时区很重要,则可以在此处阅读时区文档以在该字符串中启用它。
var abbrs = { IST : 'Indian Standard Time' }; moment.fn.zoneName = function () { var abbr = this.zoneAbbr(); return abbrs[abbr] || abbr; }; console.log(moment.tz(moment.unix(1527140580),"Asia/Calcutta").format('ddd MMMM D YYYY HH:mm:ss [GMT]ZZ (zz)'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.16/moment-timezone-with-data.min.js"></script>
const result = moment(1527140580);
result.toString() // "Sun Jan 18 1970 21:42:20 GMT+0530"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.