Python 3 - Datetime.now()日期不正确

时间:2018-04-29 18:21:19

标签: python python-3.x

<!DOCTYPE html>
<html>
<head>
    <title>Location tracking Google map</title>
</head>
<body>
    <h1>Location tracking Google Map</h1>

    <!-- testing, next 3 lines can be removed -->
    <h4>Testing variables (these latlngs have no effect on the map):</h4>
    <p id="responsecontainer"></p>
    <p id="responsecheck"></p>

    <!-- the map -->
    <div id="map" style="width:600px;height:400px">My map will go here</div>

</body>
</html>

<!-- the scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    //Global variables for map and marker
    var map;
    var marker;
    //function to set uo the map
    function myMap() {
        var mapOptions = {
            center: new google.maps.LatLng(51.5, -0.12),
            zoom: 10,
            mapTypeId: google.maps.MapTypeId.HYBRID
        }
        map = new google.maps.Map(document.getElementById("map"), mapOptions);
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(51.5, -0.12),
            map: map,
            title: 'Initial marker!'
          });
    }
    //jQuery and ajax call to get new location location
    $(document).ready(function() {
        $(function retrieveData(){
           $.ajax({    //create an ajax request to display.php
              type: "GET",
              url: "retrievedata.php",
              dataType: "html",   //expect html to be returned
              success: function(response){

                  var res = response.split(",");
                  myLat = res[0];
                  myLng = res[1];
                  point = new google.maps.LatLng(myLat, myLng);
                  map.setCenter(point);
                  changeMarkerPosition(marker, point);

                  //testing - next two lines can be removed
                  $("#responsecontainer").html(response);
                  $("#responsecheck").html("myLat: " + myLat + ", myLng: " + myLng);
              }
          });
          timerId = setTimeout(retrieveData, 1000);
        });
    });
    //function to update marker location on map
    function changeMarkerPosition(mymarker, location){
        mymarker.setPosition(location);
    }
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIsCXBsss2UeKrP80RfU-webxxV757b3j9vubcc&callback=myMap"></script>

结果为:2018.04.29-03:43:52,而正确的时间应为:2018.04.28-22:43:52

有关如何纠正/解决此问题的任何想法?

3 个答案:

答案 0 :(得分:0)

你为什么不用时间:

import time
time.time()
trime.ctime()

答案 1 :(得分:0)

它正在我的电脑上工作:

>>> from datetime import datetime
>>> currentTime = datetime.now()
>>> picTime = currentTime.strftime("%Y.%m.%d-%H%M%S")
>>> picTime
'2018.04.29-203446'

(这是我当地的时间)

一种可能的解释是,您的计算机上没有正确配置时间。

答案 2 :(得分:0)

您可能处于虚拟化环境(如泊坞窗),并且您的虚拟时区与主机中的时区不同。

您最好的方法是手动指定时区here