I think your date comes from php and is written to html (dom) or? I have a php-function to prep all dates and timestamps. This return a formation that is be needed.
$timeForJS = timeop($datetimeFromDatabase['payedon'], 'js', 'local'); // save 10/12/2016 09:20 on var
this format can be used on js to create new Date...
<html>
<span id="test" data-date="<?php echo $timeForJS; ?>"></span>
<script>var myDate = new Date( $('#test').attr('data-date') );</script>
</html>
What i will say is, make your a own function to wrap, that make your life easyr. You can us my func as sample but is included in my cms you can not 1 to 1 copy and paste :)
function timeop($utcTime, $for, $tz_output = 'system')
{
// echo "<br>Current time ( UTC ): ".$wwm->timeop('now', 'db', 'system');
// echo "<br>Current time (USER): ".$wwm->timeop('now', 'db', 'local');
// echo "<br>Current time (USER): ".$wwm->timeop('now', 'D d M Y H:i:s', 'local');
// echo "<br>Current time with user lang (USER): ".$wwm->timeop('now', 'datetimes', 'local');
// echo '<br><br>Calculator test is users timezone difference != 0! Tested with "2014-06-27 07:46:09"<br>';
// echo "<br>Old time (USER -> UTC): ".$wwm->timeop('2014-06-27 07:46:09', 'db', 'system');
// echo "<br>Old time (UTC -> USER): ".$wwm->timeop('2014-06-27 07:46:09', 'db', 'local');
/** -- */
// echo '<br><br>a Time from db if same with user time?<br>';
// echo "<br>db-time (2019-06-27 07:46:09) time left = ".$wwm->timeleft('2019-06-27 07:46:09', 'max');
// echo "<br>db-time (2014-06-27 07:46:09) time left = ".$wwm->timeleft('2014-06-27 07:46:09', 'max', 'txt');
/** -- */
// echo '<br><br>Calculator test with other formats<br>';
// echo "<br>2014/06/27 07:46:09: ".$wwm->ntimeop('2014/06/27 07:46:09', 'db', 'system');
switch($tz_output){
case 'system':
$tz = 'UTC';
break;
case 'local':
$tz = $_SESSION['wwm']['sett']['tz'];
break;
default:
$tz = $tz_output;
break;
}
$date = new DateTime($utcTime, new DateTimeZone($tz));
if( $tz != 'UTC' ) // Only time converted into different time zone
{
// now check at first the difference in seconds
$offset = $this->tz_offset($tz);
if( $offset != 0 ){
$calc = ( $offset >= 0 ) ? 'add' : 'sub';
// $calc = ( ($_SESSION['wwm']['sett']['tzdiff'] >= 0 AND $tz_output == 'user') OR ($_SESSION['wwm']['sett']['tzdiff'] <= 0 AND $tz_output == 'local') ) ? 'sub' : 'add';
$offset = ['math' => $calc, 'diff' => abs($offset)];
$date->$offset['math']( new DateInterval('PT'.$offset['diff'].'S') ); // php >= 5.3 use add() or sub()
}
}
// create a individual output
switch( $for ){
case 'js':
$format = 'm/d/Y H:i'; // Timepicker use only this format m/d/Y H:i without seconds // Sett automatical seconds default to 00
break;
case 'js:s':
$format = 'm/d/Y H:i:s'; // Timepicker use only this format m/d/Y H:i:s with Seconds
break;
case 'db':
$format = 'Y-m-d H:i:s'; // Database use only this format Y-m-d H:i:s
break;
case 'date':
case 'datetime':
case 'datetimes':
$format = wwmSystem::$languages[$_SESSION['wwm']['sett']['isolang']][$for.'_format']; // language spezific output
break;
default:
$format = $for;
break;
}
$output = $date->format( $format );
/** Replacement
*
* D = day short name
* l = day long name
* F = month long name
* M = month short name
*/
$output = str_replace([
$date->format('D'),
$date->format('l'),
$date->format('F'),
$date->format('M')
],[
$this->trans('date', $date->format('D')),
$this->trans('date', $date->format('l')),
$this->trans('date', $date->format('F')),
$this->trans('date', $date->format('M'))
], $output);
return $output; // $output->getTimestamp();
}