Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';我无法在Android中获得Phone Gap来提供当前时间_Javascript_Android_Mobile_Cordova - Fatal编程技术网

Javascript Can';我无法在Android中获得Phone Gap来提供当前时间

Javascript Can';我无法在Android中获得Phone Gap来提供当前时间,javascript,android,mobile,cordova,Javascript,Android,Mobile,Cordova,我正在使用Phone Gap开发一个Android应用程序,在获取javascript文件中的当前时间时遇到问题 我尝试过使用标准的Date()调用,但一无所获 function getCurrentTime(){ //get current time var currentTime = new Date(); var timestamp = JSON.stringify(currentTime); console.log('current time: ', timestamp); } 打印当

我正在使用Phone Gap开发一个Android应用程序,在获取javascript文件中的当前时间时遇到问题

我尝试过使用标准的Date()调用,但一无所获

function getCurrentTime(){
//get current time
var currentTime = new Date();
var timestamp = JSON.stringify(currentTime);
console.log('current time: ', timestamp);
}
打印当前时间:

我在phonegap文档中找到的唯一其他参考是:

var onSuccess = function(position) {
    alert('Latitude: '          + position.coords.latitude          + '\n' +
          'Longitude: '         + position.coords.longitude         + '\n' +
**********'Timestamp: '         + new Date(position.timestamp)      + '\n');
};

//
function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
}

navigator.geolocation.getCurrentPosition(onSuccess, onError);
我试过用它,但它还是不打印。有什么想法吗

    var success = function(p) {
        bkme.flags.gettingLocation = false;
        bkme.data.geolocation = {
            'lat' : p.coords.latitude,
            'lon' : p.coords.longitude,
            'accuracy' : p.coords.accuracy,
            'valid' : true
        };

        console.log('time:', new Date(p.timestamp));


    };
    var fail = function(error) { };

    navigator.geolocation.getCurrentPosition(success, fail);

你试过跳过JSON.stringify调用吗?

这是我在应用程序中使用的,效果很好

var date = new Date();
var hour = date.getHours();
var min = date.getMinutes();
var seconds = date.getSeconds();

希望对您有所帮助

您在哪里测试应用程序??您能否指定正在测试的版本以及在应用程序中所做的任何其他设置?您是否尝试过其他手机?Android浏览器是高度碎片化的,可能存在一些问题。。。