Link to home
Create AccountLog in
Avatar of rtod2
rtod2Flag for United States of America

asked on

save time zone

I need the following for my wordpress site.
1. Something that shows my time with a label (i.e. This is My Time CST -6).
2. Something that will allow an outsourcer to select their time from a list on the front-end, and save it on the page for easy reference.
ASKER CERTIFIED SOLUTION
Avatar of Kalpan
Kalpan
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of rtod2

ASKER

Thank you for the code.  I have never done anything with cookies so I wouldn't know how to implement your suggestion.

From the back-end of Wordpress, I would:
1) Add New Page
2) Paste code ??

Your assistance is greatly appreciated.
You might want to hire a professional developer to help with this.  It's not completely simple.

The PHP and MySQL part of things are explained here:
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

HTH, ~Ray
Avatar of rtod2

ASKER

Maybe part one is just to show 'my time' statically.  Can I do that without code?
"without code?" - Uhh, maybe you mean "In JavaScript without any modifications to PHP on the server?"
Avatar of rtod2

ASKER

Not sure what I mean.  What are the steps to get "My Time" to show up on the page.

Example:

1. My Time is -6 UTC and is currently ??

What is Your Time currently ??

If I could set 1 up then I can take it from there and figure out a workable solution.

<?php // RAY_easy_client_time.php
error_reporting(E_ALL);


// USE JAVASCRIPT TO GET THE CLIENT TIME AND COMPUTE THE OFFSET FROM THE SERVER TIME


// LOCATION OF THE SERVER - COULD BE ANYWHERE
date_default_timezone_set('America/Denver');

// DIFFERENCE OF SERVER TIME FROM UTC
$server_offset_seconds = date('Z');

// WHEN THE FORM IS SUBMITTED
if (!empty($_POST))
{
    // JAVASCRIPT TELLS US THE CLIENT TIME OFFSET FROM GMT / UTC
    $client_offset_minutes = $_POST["date_O"];
    $client_offset_seconds = $client_offset_minutes * 60;

    // THE TIME WE WANT AT THE CLIENT LOCATION
    $client_timestring = 'TODAY 7:00AM';

    // MAKE THE COMPUTATIONS, INCORPORATING THE OFFSET FROM GMT
    $client_timestamp  = strtotime($client_timestring) + $client_offset_seconds;
    $server_timestamp  = $client_timestamp + $server_offset_seconds;
    $server_timestring = date('l, F j, Y \a\t g:i a', $server_timestamp);

    echo "<br/>ACCORDING TO THE VALUE FROM PHP date Z";
    echo "<br/>SERVER IS LOCATED $server_offset_seconds SECONDS FROM UTC";
    echo "<br/>";

    echo "<br/>ACCORDING TO THE VALUE FROM JS dateObject.getTimezoneOffset()";
    echo "<br/>CLIENT IS LOCATED $client_offset_minutes MINUTES FROM UTC";
    echo "<br/>";

    echo "<br/>WHEN IT IS '$client_timestring' AT THE CLIENT, IT IS '$server_timestring' IN " . date_default_timezone_get();
}

// END OF PHP - USE HTML AND JS TO CREATE THE FORM
echo PHP_EOL; ?>

<form method="post">
<input name="date_O" id="dateTime_O" type="hidden" />
<input type="submit" value="CHECK CLIENT DATETIME" />
</form>

<!-- NOTE THIS WILL GIVE YOU THE VALUES AT PAGE-LOAD TIME, NOT AT SUBMIT TIME -->
<!-- MAN PAGE REF: http://www.w3schools.com/jsref/jsref_obj_date.asp -->
<script type="text/javascript">
var dateObject = new Date();
document.getElementById("dateTime_O").value = dateObject.getTimezoneOffset();
</script>

Open in new window

Avatar of rtod2

ASKER

Need something simpler than that.  This is making a mountain out of a molehill I think.  Sorry to put it like that.  I do appreciate all the help!
As I wrote above, "You might want to hire a professional developer to help with this.  It's not completely simple."

It doesn't get any simpler than that.  Install the script on your server and run it to see the moving parts.  Watch the values that you get from running it and you should be able to see how it works.
Avatar of rtod2

ASKER

Would I paste your code here
del.png
Please hire a professional developer to help with this.  I have shown you the principles, but if you cannot implement them, then it's not really a question as much as it is a need for an application developer -- to modify your current (working) code.  Suggest you get on Facebook and look up Aaron Brazell.  I know him personally - tell him I sent you.  He is a good guy and he recently wrote a book on Wordpress.  Located in Austin, TX, Central Standard Time (UTC - ?).  Aaron is not cheap, but he is the best in the game and you will get good and timely results.  Show him the communications we have shared here.  You'll have a clearheaded working solution in an hour or two!

Good luck and Happy New Year, ~Ray
Avatar of rtod2

ASKER

Well the question for this is certainly not something I would pay for but I might indeed be interested in having him tell me what he can do for me.

In terms of this question, it is still pending.
Avatar of rtod2

ASKER

Your code below produced a button at the bottom here >> http://tedpenner.com/test-clock/ but the rest of it is still troubling.
<?php // RAY_easy_client_time.php
error_reporting(E_ALL);


// USE JAVASCRIPT TO GET THE CLIENT TIME AND COMPUTE THE OFFSET FROM THE SERVER TIME


// LOCATION OF THE SERVER - COULD BE ANYWHERE
date_default_timezone_set('America/Denver');

// DIFFERENCE OF SERVER TIME FROM UTC
$server_offset_seconds = date('Z');

// WHEN THE FORM IS SUBMITTED
if (!empty($_POST))
{
    // JAVASCRIPT TELLS US THE CLIENT TIME OFFSET FROM GMT / UTC
    $client_offset_minutes = $_POST["date_O"];
    $client_offset_seconds = $client_offset_minutes * 60;

    // THE TIME WE WANT AT THE CLIENT LOCATION
    $client_timestring = 'TODAY 7:00AM';

    // MAKE THE COMPUTATIONS, INCORPORATING THE OFFSET FROM GMT
    $client_timestamp  = strtotime($client_timestring) + $client_offset_seconds;
    $server_timestamp  = $client_timestamp + $server_offset_seconds;
    $server_timestring = date('l, F j, Y \a\t g:i a', $server_timestamp);

    echo "<br/>ACCORDING TO THE VALUE FROM PHP date Z";
    echo "<br/>SERVER IS LOCATED $server_offset_seconds SECONDS FROM UTC";
    echo "<br/>";

    echo "<br/>ACCORDING TO THE VALUE FROM JS dateObject.getTimezoneOffset()";
    echo "<br/>CLIENT IS LOCATED $client_offset_minutes MINUTES FROM UTC";
    echo "<br/>";

    echo "<br/>WHEN IT IS '$client_timestring' AT THE CLIENT, IT IS '$server_timestring' IN " . date_default_timezone_get();
}

// END OF PHP - USE HTML AND JS TO CREATE THE FORM
echo PHP_EOL; ?>

<form method="post">
<input name="date_O" id="dateTime_O" type="hidden" />
<input type="submit" value="CHECK CLIENT DATETIME" />
</form>

<!-- NOTE THIS WILL GIVE YOU THE VALUES AT PAGE-LOAD TIME, NOT AT SUBMIT TIME -->
<!-- MAN PAGE REF: http://www.w3schools.com/jsref/jsref_obj_date.asp -->
<script type="text/javascript">
var dateObject = new Date();
document.getElementById("dateTime_O").value = dateObject.getTimezoneOffset();
</script>

Open in new window

Avatar of rtod2

ASKER

Here it is a test site.  Not exactly what I was after but a good tool none-the-less.  I tried to make the question clearer here >>  http://onodot.com/xtro
At http://tedpenner.com/test-clock/ it appears that you have pasted my code into a text area of an HTML page.  What were you expecting?  It is a standalone PHP script that is a teaching demonstration of how to get the client's time from the client's computer.  You just install it and run it.  Here is a link to the example:
http://www.laprbass.com/RAY_easy_client_time.php

Regarding this, "In terms of this question, it is still pending." -- That is why you need to hire a professional developer!  The question is completely answered, with working and tested demonstration code, and now all you need is someone to take the knowledge demonstrated in that answer and integrate it into your unique application environment.  I can only teach the principles; I can't do application changes for you.
onodot.png
Sidebar note... WordPress is written in PHP.   If you decide you want to learn PHP, this is a really good book to get you started.
http://www.sitepoint.com/books/phpmysql4/
Avatar of rtod2

ASKER

Thanks Ray,
I'm new to this.  This project is not up for hire.  Thank you for the learning resources.