How to display the current time in PHP in real time

Source: Internet
Author: User
01.<?php
02.header (' CONTENT-TYPE:TEXT/HTML;CHARSET=GBK ');
03.date_default_timezone_set (' PRC ');
$n =CHR (13);
05.echo "<script language=\" javascript\ ">". $n;
06.echo "document.write (' <div id=\" timeshow\ "align=\" right\ "style=\" MARGIN-RIGHT:0PX;FONT-SIZE:9PT; Font-family: Song body \ ">?</div>"); $n;
07.echo "var y=". Date ("Y"). "; Year ". $n;
08.echo "var m=". Date ("n"). "; Month ". $n;
09.echo "var d=". Date ("J"). "; Day ". $n;
10.echo "var w=". Date ("W"). "; Star ". $n;
11.echo "var h=". Date ("H"). "; When ". $n;
12.echo "var i=". Date ("I"). "; Points ". $n;
13.echo "var s=". Date ("S"). "; Seconds ". $n;
14.echo "var hstr=istr=sstr=a= ';". $n;
15.echo "var ww = Array (' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ');" $n;
16.echo "function clock () {". $n;
17.echo "s++". $n;
18.echo ' if (s==60) {i+=1;s=0} Seconds carry ". $n;
19.echo ' if (i==60) {h+=1;i=0} Sub-carry ". $n;
20.echo ' if (h==24) {w+=1;d+=1;h=0} Time rounding ". $n;
21.echo ' if (w==7) {w=0} Weekly rounding ". $n;
22.echo ' if (m==2) {//is February? ". $n;
23.echo "if (!y%4>0) {//Not leap month (28 days in February)". $n;
24.echo "if (d==30) {". $n;
25.echo "M+=1". $n;
26.echo "d=1;}". $n;
27.echo "}". $n;
28.echo "Else {//is a leap month (29 days in February)". $n;
29.echo "if (d==29) {". $n;
30.echo "M+=1". $n;
31.echo "d=1;}". $n;
32.echo "}". $n;
33.echo "}". $n;
34.echo "Else {//Non February months". $n;
35.echo "If" (m==4 | | m==6 | | m==9 | | m==11) {//Only 30 days of the Month ". $n;
36.echo "if (d==31) {". $n;
37.echo "M+=1". $n;
38.echo "d=1;}". $n;
39.echo "}". $n;
40.echo "Else {//There are 31 days of the month". $n;
41.echo "if (d==32) {". $n;
42.echo "M+=1". $n;
43.echo "d=1;}". $n;
44.echo "}". $n;
45.echo "}". $n;
46.echo ' if (m==13) {y+=1;m=1} Monthly carry ". $n;
47.echo "if (H <) {hstr= ' 0 ' +h} else {hstr= ' +h};". $n;
48.echo "if (I < ten) {istr= ': 0 ' +i} else {istr= ': ' +i};". $n;
49.echo "if (S <) {sstr= ': 0 ' +s} else {sstr= ': ' +s};". $n;
50.echo ' if (H <) {astr= ' AM ';} else {astr= ' PM ';}; ". $n;
51.echo "timeshow.innerhtml=y+ ' year ' +m+ ' month ' +d+ ' Day ' + ' <font color= #66FFFF > Week ' +ww[w]+ ' </font> ' +hstr+istr+ Sstr+astr; ". $n;
52.echo "settimeout (' clock () ', 1000);". $n;
53.echo "}". $n;
54.echo "clock ();". $n;
55.echo "</SCRIPT>" $n;
56.?>

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.