简体   繁体   English

不同国家/地区的完整日历日期不同

[英]Full Calendar Dates are different in different countries

I am using fullcalendar.js and i am having problem with the timezone. 我正在使用fullcalendar.js,时区有问题。 It is working perfectly well from where i am living but my client who lives in Canada Burlington doesn't get the same date he clicks on. 从我居住的地方来看,它运行得非常好,但是我居住在加拿大伯灵顿市的客户没有获得相同的点击日期。 i have set the zone to -05:00(their zone) but doesn't help, is there a way to set the timezone to local? 我已将区域设置为-05:00(其区域),但无济于事,有没有办法将时区设置为本地? so no matter where you access the full calendar it show. 因此无论您在哪里访问显示的完整日历。

在此处输入图片说明

These dates that are highlited are shown as 6 in Canada, on the same date clicked. 这些高亮显示的日期在加拿大与单击相同的日期显示为6。

this is the code i'm using to open the modal on dayclick 这是我用来在dayclick上打开模式的代码

   dayClick: function(date, jsEvent, view) {
    var click = date._d;
    var month = new Array();
    month[0] = "January";
    month[1] = "February";
    month[2] = "March";
    month[3] = "April";
    month[4] = "May";
    month[5] = "June";
    month[6] = "July";
    month[7] = "August";
    month[8] = "September";
    month[9] = "October";
    month[10] = "November";
    month[11] = "December";
    var weekday = new Array(7);
    weekday[0]=  "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";
    $("#myModal").modal("show");

    document.getElementById("date").setAttribute("value", click.getFullYear() +"-"+ ("0"+ (click.getMonth()+1)).slice(-2)+"-"+("0" + click.getDate()).slice(-2));

    document.getElementById("month").setAttribute("value", month[click.getMonth()]);
    document.getElementById("str_day").setAttribute("value", ("0" + click.getDate()).slice(-2));
    document.getElementById("end_day").setAttribute("value", weekday[click.getDay()]);
  },
  eventResize: function(event, delta, revertFunc) {
    console.log(event);
    var title = event.title;
    var end = event.end.format();
    var start = event.start.format();
    $.ajax({
      url: 'fullcalender/process.php',
      data: 'type=resetdate&title='+title+'&start='+start+'&end='+end+'&eventid='+event.id,
      type: 'POST',
      dataType: 'json',
      success: function(response){
        if(response.status != 'success')
          revertFunc();
      },
      error: function(e){
        revertFunc();
        alert('Error processing your request: '+e.responseText);
      }
    });

And this is the code used to add in the database 这是用于添加到数据库中的代码

if($type == 'new')
{
    $startdate = $_POST['startdate'].'+'.$_POST['zone'];
    $title = $_POST['title'];
    $insert = mysqli_query($con,"INSERT INTO calendar(`title`, `startdate`, `enddate`, `allDay`) VALUES('$title','$startdate','$startdate','false')");
    $lastid = mysqli_insert_id($con);
    echo json_encode(array('status'=>'success','eventid'=>$lastid));
}

As far as storing your times, they should be stored as UTC timestamp. 至于存储您的时间,它们应该存储为UTC时间戳。 For retrieving the timezone I use jstz to get the users timezone, its as simple as these two lines. 为了获取时区,我使用jstz来获取用户的时区,它与这两行一样简单。

var tz = jstz.determine();
var timezone = tz.name();

This will give you a timezone like "America/Chicago" for wherever the user is, this is great because you dont have to ask the user for their timezone and it will work anywhere. 无论用户身在何处,这都会为您提供一个类似于“ America / Chicago”的时区,这很棒,因为您不必询问用户的时区,它就可以在任何地方使用。 Then pass your timezone along with your request for events and you can use your server side language for converting from UTC to the supplied timezone when retrieving events. 然后将您的时区与事件请求一起传递,并且可以在检索事件时使用服务器端语言将UTC转换为提供的时区。

events: {
    url: "calendarManager.php?request=get&timezone=" + timezone + "&userid=" + userID
},

You should also use 您还应该使用

timezone: "local",

in your calendar configuration and then convert from UTC to the users local timezone when returning events using the method above. 在您的日历配置中,然后在使用上述方法返回事件时,从UTC转换为用户本地时区。

我实际上在3天后发现了问题,问题是我正在使用getDate(),使用getUTCDat()解决了这个问题:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM