私は、タイムゾーン(req.body.TIMEZONE)とフォームからdatetime開始 - 終了を取ります。私は時間を表示して、Icalファイルを作成しようとしていますが、新しいDate(文字列)を実行するたびに7時間前に取得しますか?私は瞬間を使用しようとしていますか?どのようにして、ローカルファイルをユーザーのローカルファイルに表示できますか?Icalファイルの日時解析
var cal = ical();
cal.domain('gmail.com');
var dateFormat = 'YYYY-DD-MM HH:mm+00:00';
console.log(req.body.START_TIME); //2016-10-03 10:40 am
var startTime = moment(req.body.START_TIME);
var localDateStart = startTime.local();
console.log(localDateStart.format(dateFormat)); // 2016-03-10 10:40+00:00
console.log(new Date(localDateStart.format(dateFormat))); // invalid... wants the same time
var endTime = moment(req.body.END_TIME);
var localDateEnd = endTime.local();
console.log(localDateEnd.format(dateFormat));
var event = cal.createEvent({
start: new Date(localDateStart.format(dateFormat)),
end: new Date(localDateEnd.format(dateFormat)),
summary: req.body.TITLE,
location: req.body.LOCATION,
description: req.body.DESCRIPTION,
organizer: req.body.HOSTED + " <" + req.body.EMAIL + ">",
url: req.body.URL
});
、 '新しい日付(req.body.START_TIME)の結果は'実装に依存示さ形式で与えられました。なぜライブラリを使用して文字列を解析するのですか? – RobG
@RobG私は同じ変数を再割り当てするために解析しているので、常に瞬間を使用しています。しかし、リアルタイムが戻ってきますが、GMTで表示されたときにPSTが必要です。 –
あなたは「常に瞬間を使用している」わけではありません。 * new Date(localDateStart.format(dateFormat)) 'で、* localDateStart *が瞬間オブジェクトであると仮定すると、文字列を生成するために瞬間を使用し、* Date *解析することは非常に悪い考えです。代わりに 'localDateStart.clone()'を使用してください。[* moment clone *](http://momentjs.com/docs/#/parsing/moment-clone/)を参照してください。 – RobG