Reputation: 729
I need to get the current time. This code works perfect in a browser but does not work in a phonegap app for iOS. Is there anything I should do different within my Javascript to make this work using phonegap?
var dt = new Date();
currentHours = dt.getHours();
currentHours = ("0" + currentHours).slice(-2);
currentMinutes = dt.getMinutes();
currentMinutes = ("0" + currentMinutes).slice(-2);
currentSeconds = dt.getSeconds();
currentSeconds = ("0" + currentSeconds).slice(-2);
var time = currentHours+":"+currentMinutes+":"+currentSeconds;
var formData = $(this).serialize() + '&time=' + time;
Upvotes: 0
Views: 1896
Reputation: 3988
That has to work, check if the hour of the emulator is right (The timezone can be incorrect).
Anyway, I recommend you use the UTC timestamp like:
var dt = new Date();
var now = dt.getTime();
var formData = $(this).serialize() + '&time=' + now.toString();
Other solution is using moment.js lib, ex:
var formData = $(this).serialize() + '&time=' + moment().format("HH:MM:SS");
Upvotes: 3