Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

momentjs - Moment startOf date starts at 8AM

I noticed this while trying to do a compare.

const elevenMthsAgoS = moment().subtract(11, "months").startOf("date");

Returns the date eleven months ago but at 8AM? How can I get it to 000 the time. Should I do end of date on day before? Or is there a better way?

question from:https://stackoverflow.com/questions/65850912/moment-startof-date-starts-at-8am

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you use moment or moment-timezone?

I run follow lines now maybe help you :

var moment = require("moment");
var momentTimezone = require("moment-timezone");

const elevenMthsAgoS = moment().subtract(11, "months").startOf("date");

console.log(elevenMthsAgoS);           // Moment<2020-02-25T00:00:00+03:30>
console.log(elevenMthsAgoS.format());  // 2020-02-25T00:00:00+03:30


var jun = momentTimezone("2014-06-01T12:00:00Z");
var dec = momentTimezone("2014-12-01T12:00:00Z");

console.log(jun.tz('America/Los_Angeles').format('ha z'));  // 5am PDT
console.log(dec.tz('America/Los_Angeles').format('ha z'));  // 4am PST

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...