admin管理员组文章数量:1023772
I want to subtract 1 day from the time now in a different timezone. The moment.js docs say to use referenceTime as the time to subtract one day from. The code below prints the current time in Los Angeles (first) and then the the time 1 day ago from today in the timezone I am currently in (second), I want it to print the time 1 day ago from the timezone in Los Angeles.
require moment = require('moment'),
moment_tz = require('moment-timezone');
var referenceTime = moment_tz().tz("America/Los_Angeles").format();
console.log(referenceTime);
var referenceTimeMinusOne = moment().subtract(1,'days').calendar(referenceTime);
console.log(referenceTimeMinusOne);
I want to subtract 1 day from the time now in a different timezone. The moment.js docs say to use referenceTime as the time to subtract one day from. The code below prints the current time in Los Angeles (first) and then the the time 1 day ago from today in the timezone I am currently in (second), I want it to print the time 1 day ago from the timezone in Los Angeles.
require moment = require('moment'),
moment_tz = require('moment-timezone');
var referenceTime = moment_tz().tz("America/Los_Angeles").format();
console.log(referenceTime);
var referenceTimeMinusOne = moment().subtract(1,'days').calendar(referenceTime);
console.log(referenceTimeMinusOne);
Share
Improve this question
asked Nov 21, 2014 at 0:24
jacob30jacob30
1511 gold badge3 silver badges11 bronze badges
1 Answer
Reset to default 2It doesn't matter, it operates on UTC and converts afterwards.
moment = require('moment-timezone');
var la = moment().tz("America/Los_Angeles")
var nl = moment().tz("Europe/Amsterdam")
console.log('now:')
console.log(la.format());
console.log(nl.format());
var earlier_la = la.subtract(1,'days')
var earlier_nl = nl.subtract(1,'days')
console.log('\nearlier:')
console.log(earlier_la.format());
console.log(earlier_nl.format());
// Earlier Dutch time converted back to Los Angelos equals
// Earlier Los Angelos time
console.log(earlier_nl.tz('America/Los_Angeles').format());
I want to subtract 1 day from the time now in a different timezone. The moment.js docs say to use referenceTime as the time to subtract one day from. The code below prints the current time in Los Angeles (first) and then the the time 1 day ago from today in the timezone I am currently in (second), I want it to print the time 1 day ago from the timezone in Los Angeles.
require moment = require('moment'),
moment_tz = require('moment-timezone');
var referenceTime = moment_tz().tz("America/Los_Angeles").format();
console.log(referenceTime);
var referenceTimeMinusOne = moment().subtract(1,'days').calendar(referenceTime);
console.log(referenceTimeMinusOne);
I want to subtract 1 day from the time now in a different timezone. The moment.js docs say to use referenceTime as the time to subtract one day from. The code below prints the current time in Los Angeles (first) and then the the time 1 day ago from today in the timezone I am currently in (second), I want it to print the time 1 day ago from the timezone in Los Angeles.
require moment = require('moment'),
moment_tz = require('moment-timezone');
var referenceTime = moment_tz().tz("America/Los_Angeles").format();
console.log(referenceTime);
var referenceTimeMinusOne = moment().subtract(1,'days').calendar(referenceTime);
console.log(referenceTimeMinusOne);
Share
Improve this question
asked Nov 21, 2014 at 0:24
jacob30jacob30
1511 gold badge3 silver badges11 bronze badges
1 Answer
Reset to default 2It doesn't matter, it operates on UTC and converts afterwards.
moment = require('moment-timezone');
var la = moment().tz("America/Los_Angeles")
var nl = moment().tz("Europe/Amsterdam")
console.log('now:')
console.log(la.format());
console.log(nl.format());
var earlier_la = la.subtract(1,'days')
var earlier_nl = nl.subtract(1,'days')
console.log('\nearlier:')
console.log(earlier_la.format());
console.log(earlier_nl.format());
// Earlier Dutch time converted back to Los Angelos equals
// Earlier Los Angelos time
console.log(earlier_nl.tz('America/Los_Angeles').format());
版权声明:本文标题:javascript - Subtract 1 day from date in different timezone using moment.js and moment-timezone.js - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745562868a2156269.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论