0

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 ?>

1
  • 2
    Your question is "How can I create an UTC date in PHP"? Commented Jul 20, 2011 at 9:14

4 Answers 4

2

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()

Sign up to request clarification or add additional context in comments.

1 Comment

I really liked the nice simple javascript converter I found. I guess you're right i'll just have to covert the date string 07/20/2011 01:13 am to UTC using php. Any ideas how I might convert a string like that to UTC?
1

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'));

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.