使用moment.js尝试在本机IOS日历中创建事件 [英] Using moment.js trying to create an event in native IOS calendar

查看:357
本文介绍了使用moment.js尝试在本机IOS日历中创建事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用datetime-local输入来获取用户的开始日期和结束日期以放入本机日历。这是我获取和格式化datetime-local的代码:

I have used the "datetime-local" input to get a start date and an end date from the user to put into the native calendar. This is my code to get and format the "datetime-local":

    var s = $("#startDate").val();
    var startDate = moment(s).toDate();
    var e = $("#endDate").val();
    var endDate = moment(s).toDate();

此代码采用正确的日期,但它将时间设置为全天事件。例如,如果我在2014年7月21日的1:00作为开始日期,然后在2014年7月22日的1:00,它将在7/21/2014创建一整天的活动。

This code takes the correct date, but it makes the time set to an all day event. For example, if I put in 1:00 o'clock on 7/21/2014 as the start date and then 1:00 o'clock on 7/22/2014 it will create an all day event on 7/21/2014.

这是 JSFiddle

推荐答案

您似乎有拼写错误。传递 e 来构建 endDate ,而不是 s

You appear to have a typo. Pass e to build the endDate, not s.

var s = $("#startDate").val();
var startDate = moment(s).toDate();
var e = $("#endDate").val();
var endDate = moment(e).toDate(); // <==== this line had used the wrong variable

或者,你可以改为调用这些内联以避免混淆:

Or, you could instead just call these inline to avoid confusion:

var startDate = moment($("#startDate").val()).toDate();
var endDate = moment($("#endDate").val()).toDate();

至于为什么这会创造一个全天活动 - 我不能绝对肯定,因为我我不熟悉您正在使用的特定日历API。但是,由于您发送相同的开始和结束时间,因此它可能会将其解释为全天事件。我相信修正错字会解决这个问题。

As to why this created an "all day event" - I can't be absolutely certain since I'm not familiar with the particular calendar API you're using. However, it's possible that since you were sending the same start and end time, that it interpreted that as an all day event. I believe fixing the typo will solve the issue.

这篇关于使用moment.js尝试在本机IOS日历中创建事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆