开发者

How to use javascript vars in php?

Here's what im trying to do

<?php
    //get time from what user input on post
    $time = $_POST['time'];开发者_开发技巧

 ?>
            <script type="text/javascript">
                 //convert time to utc
                 var convertedDate = dateFormat('<?php echo $time ?>', 'isoUtcDateTime');       
            </script> 
  <?php 
       $query = "INSERT INTO $table (url, time) VALUES ('$url', 'convertedDate');";
        mysql_query($query);
  ?>

I know you can't just place convertedDate in there like that, so what im asking is how would I go about doing the javascript equivalent of what i did with <?php echo $time ?>


Format date in PHP, with date() or DateTite object.

If you need to store other items like that, but not sa simple and JS-dependent, you should do a AJAX request to php file to store it, it's simple with jQuery and .ajax()


If you need to convert date in UTC.

Use gmdate

http://www.php.net/manual/en/function.gmdate.php

Latest PHP time DateTime class can also help you

$time = new DateTime(ew DateTimeZone('UTC'));


You could do it by setting up a second page containing Javascript that takes a URL query and writes the result to the page. Then use cURL to scrape the answer from the PHP.

But don't.


Take a look at the following SO question How can I easily convert dates from UTC via PHP? on converting a time to UTC in php.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜