在浏览器上,我制作了一个生成 rrule 字符串的小部件:
var rruleString = "FREQ=WEEKLY;WKST=SU;BYDAY=MO,WE,FR;BYHOUR=8;BYMINUTE=30;BYSECOND=0"
我还使用此功能从浏览器获取时区偏移量:
//This is 300 for me
var timezoneOffSet = (new Date()).getTimezoneOffset();
我将它们发送到运行 node.js 的服务器。在服务器上,我想使用 rrule 和时区偏移来生成 UTC 格式的日期列表。这是我现在的做法:
var rruleOptions = RRule.parseString(rruleString);
rruleOptions.dtstart = new Date();
rruleOptions.until = new Date();
rruleOptions.until.setMonth(options.until.getMonth() + 4);
var rule = new RRule(rruleOptions);
var dates = rule.all();
//Convert the dates into moment.js objects
momentDates = dates.map(function(date){
//This is where I think the problem is because I think moment is
//using the server's timezone
return moment(date).utcOffset(timezoneOffSet*-1);
});
//Convert the moment object array into an array of strings
var dateStringArray = momentDates.map(function(date){
//Doesn't work returns 2015-11-27T08:30:00.00Z
//return date.toISOString();
//Doesn't work returns 2015-11-27T08:30:00.00Z
//return date.utc().toISOString();
//This works returns 2015-11-27T03:30:00.00Z for one of the objects
return date.format('YYYY-MM-DDThh:mm')+":00.00Z";
});
似乎我应该能够使用不起作用的函数来获取 UTC 日期,但由于某种原因它们不起作用。我想我错过了一些关于如何使用正确的方式来做到这一点的事情。谁能看到我做错了什么?