Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sure! Use:</p> <pre><code>var JSONWithDate = { "Date": new Date(&lt;?php echo date("Y, ").(date(n) - 1).date(", j") ?&gt;) }; </code></pre> <p>EDIT: Add code example.</p> <p>Here is my code and it WORKS.</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script&gt; var J = { "Date": new Date(&lt;?php echo date("Y, ").(date("n") - 1).date(", j") ?&gt;) } document.write(J["Date"]); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>EDIT 2: Make it more like JSON.</p> <p>Here is my PHP code.</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script&gt; &lt;?php function GetJSONDate($FieldName = "Date") { return "\"$FieldName\": new Date(".date("Y, ").(date("n") - 1).date(", j").")"; } ?> function PrintJSONFromPHP(pJSONStr) { var aJSONObj = eval('('+pJSONStr+')'); document.write(aJSONObj["Date"]); } var aJSONStr = '{ &lt;?php echo GetJSONDate($FieldName = "Date"); ?&gt; }'; PrintJSONFromPHP(aJSONStr); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>It generate the following HTML code:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script&gt; function PrintJSONFromPHP(pJSONStr) { var aJSONObj = eval('('+pJSONStr+')'); document.write(aJSONObj["Date"]); } var aJSONStr = '{ "Date": new Date(2009, 8, 15) }'; PrintJSONFromPHP(aJSONStr); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>When run, it shows:</p> <pre><code>Tue Sep 15 2009 00:00:00 GMT-0600 (CST) </code></pre> <p>If you can pass a string that look like JavaScript object literal (without using variable inside it), the string can be eval to be turned to an object. This means that you can use it as JSON.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload