Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
576 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...