0

my server is on GMT -4 and all the records which go into the database are GMT -4 using

<?php date("Y-m-d H:i:s");?>

so if the time was 15:00:00 GMT +1 (my current timezone)
the time added to the database would be 10:00:00.

however when I use javascript new Date(); it gives it as

Thu Aug 29 2013 22:17:00 GMT+0100 (GMT Summer Time)

i have this function to convert the js date to php

$jsDate = $_REQUEST["date"];
$jsDateTS = strtotime($jsDate);
if ($jsDateTS !== false) 
{
$jsDateTS = date('Y-m-d H:i:s', $jsDateTS );
echo $jsDateTS."<br>";

but it writes 2013-08-29 22:17:00 and not 2013-08-28 17:17:00 which is what I need.

how do I convert my javascript new Date to GMT -4? is it possible or not?

thanks, and sorry if I am unclear in any way.

user2166538
  • 313
  • 1
  • 3
  • 18
  • You do of course realize that javascript uses the date on the visitors local computer, so whatever date and time you set in your operating system is what javascript will use. In other words, it's not reliable ? – adeneo Aug 29 '13 at 21:23
  • ok but how do I convert that date to GMT -4? – user2166538 Aug 29 '13 at 21:23
  • 1
    Why not save yourself a load of trouble and work in UTC? – Paul S. Aug 29 '13 at 21:26
  • Use the JavaScript function setTimezoneOffset if you really want to do it client-side. – dkroy Aug 29 '13 at 21:26
  • how do I convert my new Date into UTC – user2166538 Aug 29 '13 at 21:26
  • @dkroy I'm not aware of any function `setTimezoneOffset` on _Date_ or instances thereof – Paul S. Aug 29 '13 at 21:28
  • @jordanzhninja _Date_ instances in _JavaScript_ all support _UTC_ natively, it's just the `toString` which defaults to local timezone. See the MDN page of [`Date.prototype`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/prototype#Methods) for what is available to read the UTC values. – Paul S. Aug 29 '13 at 21:30
  • Regarding UTC, this might help you: http://praveenlobo.com/techblog/how-to-convert-javascript-local-date-to-utc-and-utc-to-local-date/ – Sahil Mittal Aug 29 '13 at 21:30

1 Answers1

0

my solution was the following

client side

var date = new Date();
date = date.toUTCString();

server side

$date = date('Y-m-d H:i:s', strtotime($_REQUEST["date"]) );

thanks for all others who answered

user2166538
  • 313
  • 1
  • 3
  • 18