Let's take a look at this code first.
$ (function () {
setinterval (function () {
var timer = ' <?php echo date (' y-m-d h:i:s ', Time ())?> ';
$ ("#test"). Append (timer);
},500);
};
This piece of code where there is a problem, why the page is loaded after the page has been that time will not change it? What is the difference between PHP and JS loading mechanism?
This is wrong, the PHP code is interpreted before the output, the browser received the code should be like this
$ (function () {
setinterval (function () {
var timer = ' 2015-01-02 12:02:02 ';
$ ("#test"). Append (timer);
},500);
};
So, when you're updating a fixed value,
Modified as follows
An extension to date that converts date to a string/month (M) in the specified format, days (d), hours (h), minutes (M), seconds (s), quarter (q) can be used in 1-2 placeholders,//year (Y) can be 1-4 placeholders, milliseconds (s) only 1 placeholders (yes 1-3 digits)//Example://(New Date ()). Format ("Yyyy-mm-dd hh:mm:ss. S ") ==> 2006-07-02 08:09:04.423//(New Date ()). Format ("yyyy-m-d h:m:s.s") ==> 2006-7-2 8:9:4.18 Date.prototype.Format = function (FMT) {//author:meizz var o = {"m+": This.getmonth () + 1,//month "d+": this.getdate (),//day "h+": this.gethours (),//hr "m+": This.get Minutes (),//"s+": This.getseconds (),//sec "q+": Math.floor ((This.getmonth () + 3)/3),//quarter "s": This.get
milliseconds ()//millisecond};
if (/(y+)/.test (FMT)) FMT = Fmt.replace (regexp.$1, (this.getfullyear () + ""). substr (4-regexp.$1.length)); For (var k in O) if (new RegExp ("+ K +")). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length = 1)?
(O[k]): (("+ o[k]"). substr (("" + o[k). length));
return FMT; } $ (function () {setinterval (function () {var timer = new Date (). Format ("Yyyy-mm-dd HH:mm:ss ");
$ ("#test"). Append (timer);
},500);
});