date moment 字符串 转,如何使用MomentJS将Date转换为时间戳?

I used MomentJS to convert local date to UTC date using the following way:

$("#div1").text(moment("2016-10-11 18:06:03").tz("Europe/Paris").format());

Now I need timestamp from the output value using MomentJS.

解决方案

You said:

I used MomentJS to convert local date to UTC date using the following way:

moment("2016-10-11 18:06:03").tz("Europe/Paris").format()

That doesn't do that. That converts a local value to Paris time, and emits it as a string in ISO8601 format.

Now I need timestamp from the output value using MomentJS.

That's a different question, and wouldn't involve the output of the above because:

You can't get a timestamp from the output string, you'd get it from a moment object. You could parse that string, but that would be silly since you already had a moment object earlier.

Timestamps are UTC based, so time zone conversion is irrelevant. You'd get the same timestamp if you didn't convert at all.

You can get a string with a timestamp using .format('X') or .format('x') depending on which precision you want. But it's much cleaner to just get the numerical timestamp using .valueOf() or .unix(), again depending on precision.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值