Rimi Khan
Rimi Khan

Reputation: 83

how to display strtotime in local time zone

working with a chat box where getting the msg time with raw as far I've got this $msg_time = strtotime($row["date_time"]); which is showing the strtotime values correctly. now getting confused how to show this with local timezone

Upvotes: 3

Views: 522

Answers (1)

Leandro Papasidero
Leandro Papasidero

Reputation: 3738

Server Timezone

     <?php
        // set the default timezone to use. Available since PHP 5.1
        date_default_timezone_set('UTC');

        echo date("m-d-Y", strtotime('2014-02-21')) . "timezone: " . date_default_timezone_get();

Client Timezone

file where you want to display the timezone

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Title</title>

    <!-- javascript/jQuery -->
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

    <?php
        session_start();
        echo isset($_SESSION['time']) ? $_SESSION['time'] : "error";
    ?>
</head>
<body>

<script type="text/javascript">
    $(document).ready(function () {
        var visitortime = new Date();
        var visitortimezone = "GMT " + -visitortime.getTimezoneOffset() / 60;
        $.ajax({
            type: "POST",
            url: "timezone.php?XDEBUG_SESSION_START=1",
            data: 'time=' + visitortimezone,
            success: function (data) {

            }
        });
    });
</script>
</body>
</html>

timezone.php

<?php
session_start();
$_SESSION['time'] = $_POST['time'];

Upvotes: 1

Related Questions