Question

Problem

In Android Phonegap project, I can't get the value of variable.

JavaScript Code Snippet:

var currentDate = new Date();
var dateandtime = date.trim() + "T" + time.trim() + "+0000";

var dateNew = new Date(dateandtime); 
var difference = dateNew.getTime() - (currentDate.getTime() - 120000); // New - Current - 2 minute

var time1 = difference / 1000;
alert("Seconds : " + time1);

Result:

Alert Image

If any solution for this problem then please share.
Thank you.

Was it helpful?

Solution

Try This :

var currentDate = new Date();

var arrDataOfDate = data1[0].split("-");
var arrDataOfTime = data1[1].split(":");

var year = parseInt(arrDataOfDate[0]);
var month = parseInt(arrDataOfDate[1]);
var day = parseInt(arrDataOfDate[2]);

var hours = parseInt(arrDataOfTime[0]);
var minutes = parseInt(arrDataOfTime[1]);
var seconds = parseInt(arrDataOfTime[2]);

var dateNew = new Date(year, month, day, hours, minutes, seconds);

var difference = dateNew.getTime() - (currentDate.getTime() - 120000);

var time1 = parseFloat(difference / 1000);
alert("Seconds : " + parseInt(time1));

I think problem in creation of Date Object.

OTHER TIPS

Try this:

var time1 = parseFloat(difference) / 1000;
alert("Seconds : " + parseInt(time1));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top