Change UTC date time to local date time in javascript/jquery

<?php
// php code to get current UTC date time
date_default_timezone_set('UTC');
$utcDateTime = date('Y-m-d h:m:s');
?>

<script src="http://momentjs.com/downloads/moment.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
var utcDateTime = '<?php echo $utcDateTime; ?>';

var dateTime = moment.utc(utcDateTime).toDate(); var localDateTime = moment(dateTime).format('YYYY-MM-DD HH:mm:ss');

$('#utc_date_time').html(utcDateTime);
$('#local_date_time').html(localDateTime);
});
</script>
UTC : <div id="utc_date_time"></div></br>
Local: <div id="local_date_time"></div> ...  Read More

Share This: