Google Timezone API返回错误的数据

时间:2016-12-11 03:12:39

标签: c# asp.net google-maps timezone timezone-offset

谷歌TimeZone Api为英国夏令时的rawOffset返回0小时,而根据维基百科和其他来源,BST​​(英国夏令时)比UTC早1小时。由于欧洲的夏令时在我的网站上显示错误。 enter image description here

这是打算还是我做错了什么。我的时间计算函数的正确时间如下。

function geoLoader() {
    $("#UserDetails_PlaceOfBirth").geocomplete()
    .bind("geocode:result", function (event, result) {
        $("#UserDetails_Latitude").val(result.geometry.location.lat());
        $("#UserDetails_Longitude").val(result.geometry.location.lng());
        timeZoneLoader(result.geometry.location.lat(), result.geometry.location.lng());
    })
}
function timeZoneLoader(lat, lng) {
    $.ajax({
        url: "https://maps.googleapis.com/maps/api/timezone/json?location=" + lat + "," + lng + "&timestamp=" + dateToTimeStamp($("#UserDetails_DateOfBirth").val() + " " + $("#UserDetails_TimeOfBirth").val(), 0, 0) + "&key=Your_Key",
        context: document.body
    }).done(function (data) {
        $.ajax({
            url: "https://maps.googleapis.com/maps/api/timezone/json?location=" + lat + "," + lng + "&timestamp=" + dateToTimeStamp($("#UserDetails_DateOfBirth").val() + " " + $("#UserDetails_TimeOfBirth").val(), data.rawOffset, data.dstOffset) + "&key=Your_Key",
            context: document.body
        }).done(function (data1) {
            var tzName = data1.timeZoneId + " - " + data1.timeZoneName;
            if (tzName.toLowerCase().indexOf("- gmt") != -1) {
                tzName = tzName.substring(0, tzName.toLowerCase().indexOf("- gmt"));
            }
            $("#UserDetails_TimeZone").val(tzName);
            $("#UserDetails_DayLightSavings").val(data1.dstOffset / 3600 + ':00:00');
            if (data1.rawOffset > 0) {
                $("#UserDetails_UTC").val("UTC + " + moment().startOf('day').seconds(Math.abs(data1.rawOffset)).format('HH:mm'));
            } else {
                $("#UserDetails_UTC").val("UTC - " + moment().startOf('day').seconds(Math.abs(data1.rawOffset)).format('HH:mm'));
            }
        })
    });
}
function dateToTimeStamp(date, offset, dstOffset) {
    var tzOffset = ((new Date).getTimezoneOffset()) * 60;
    var bdate = new Date(moment(date, "DD/MMM/YYYY HH:mm:ss"));
    var selSeconds = Math.floor(bdate.getTime() / 1000);
    return selSeconds - tzOffset - offset - dstOffset;
}

enter image description here

Ajax对网站上述结果的请求是:

https://maps.googleapis.com/maps/api/timezone/json?location=51.5073509,-0.12775829999998223&timestamp=1477785540&key=Your_key

0 个答案:

没有答案