Date picker output is one day ahead

We ended up writing a conversion function. The function adjusts the user selected date and time automatically to the UTC format query for a database. Here are the codes in case that somebody needs it.

var adate=flow.get('ana_date')||0; // date picker date
var atime=flow.get('ana_time')||0; // time picker time
adate=adate+atime;
var now = new Date();
var timeoffset=now.getTimezoneOffset() * 60000  // Get time zone info
var utcdate;  // UTC time for database query
if(timeoffset>0)
{
    utcdate=adate-86400000+timeoffset; 
}
else if(timeoffset<0)
{
    utcdate=adate+86400000+timeoffset; 
}
else
    utcdate=adate;
1 Like