简体   繁体   English

Moment.js与时区实时

[英]Moment.js Real time with timezone

I need to store an unix value from a Time input. 我需要存储来自时间输入的Unix值。

The problem is that : 问题是:

// I create a Moment Date from my input :
var date = moment({hour: 10, minute: 00)
// gives this _d : Mon May 04 2015 10:00:00 GMT+0200 (CEST)

// I convert it to unix value
date = date.unix()
// -> 1430726400

moment( date ).format('HH:mm')
// -> "14:25" // Should give me 10:00
// Online conversion unix time gives me : Mon, 04 May 2015 08:00:00 GMT

So how can I keep my 10:00 in memory as unix value using those transformations ? 那么如何使用这些转换将10:00作为unix值保留在内存中?

每个文档

moment.unix( date ).format('HH:mm')

I kind of sorted it this way : 我有点这样排序:

// I create a Moment Date from my input :
var date = moment({hour: 10, minute: 00)
// gives this _d : Mon May 04 2015 10:00:00 GMT+0200 (CEST)

// Convert to unix
date = date.toDate();
date = date.getTime();

console.log(moment( date ).format('HH:mm')); // Gives me 10:00

I hope it will keep the good time ? 希望它能保持美好时光? In France the time changes twice a year ( go forward 1 hour, go backwards 1 hour) 在法国,时间每年更改两次(快进1小时,快退1小时)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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