Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / November 2007



Tip: Looking for answers? Try searching our database.

server time/date

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ron Croonenberg - 29 Nov 2007 02:06 GMT
Hello,

does anyone know of a simple script to get the date and time on the
server an html document is served from ? (or a simple script to read an
html doc that only has one line in the body section ?)

thanks,

Ron
Randy Webb - 29 Nov 2007 03:50 GMT
Ron Croonenberg said the following on 11/28/2007 9:06 PM:
> Hello,
>
> does anyone know of a simple script to get the date and time on the
> server an html document is served from ? (or a simple script to read an
> html doc that only has one line in the body section ?)

Have the server put it there.

Signature

Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Ron Croonenberg - 29 Nov 2007 07:45 GMT
Hi Randy,

I did that,  but problem with that is that you don't know for how long a
page has been "sitting" there before a user does something.
(for all that I know  he/she could load a page..  and go out to lunch)

> Ron Croonenberg said the following on 11/28/2007 9:06 PM:
>> Hello,
[quoted text clipped - 4 lines]
>
> Have the server put it there.
Evertjan. - 29 Nov 2007 07:54 GMT
Ron Croonenberg wrote on 29 nov 2007 in comp.lang.javascript:

> does anyone know

This Q should really only be answered with: Yes!

> of a simple script to get the date and time on the
> server an html document is served from ?

Still, let me give an answer:

With ASP-jscript you can do:

<script language='jscript' runat='server'>
response.write(new Date());
</script>

> (or a simple script to read an
> html doc that only has one line in the body section ?)

What is an "html doc"?

Why one line? Is this a school assignment?

Signature

Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Ron Croonenberg - 29 Nov 2007 08:10 GMT
> With ASP-jscript you can do:

ASP ?  that's a windows thing...  right ?

> <script language='jscript' runat='server'>
> response.write(new Date());
[quoted text clipped - 4 lines]
>
> What is an "html doc"?

those things that you can find in the document root  of for example an
apache server ?

> Why one line? Is this a school assignment?

Uhm no...   but I can have a php script report the time, so if I can
request a "html doc"  than i can read that script's output and get the
time that way.
Randy Webb - 29 Nov 2007 09:23 GMT
Ron Croonenberg said the following on 11/29/2007 3:10 AM:

<snip>

>> Why one line? Is this a school assignment?
>
> Uhm no...   but I can have a php script report the time, so if I can
> request a "html doc"  than i can read that script's output and get the
> time that way.

function loadJSFile(fileURL){
if (document &&
    document.createElement &&
    document.appendChild &&
    document.getElementsByTagName)
 {
  var newScript = document.createElement('script');
  newScript.type = "text/javascript";
  newScript.src = fileURL;
  document.getElementsByTagName('head')[0].appendChild(newScript);
 }
}

loadJSFile('getTimeOnTheServer.php')

And then have getTimeOnTheServer.php return the time, along with a
function call to do something with the time. Instead of having PHP just
return a one line file with the time, it would look something like this:

var serverTime = <?php echo time() ?>;
someFunctionInThePageToDoSomethingWithTheTimeVariable();

Signature

Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Ron Croonenberg - 29 Nov 2007 14:58 GMT
Hi Randy,

thanks,  I really appreciate it.

> Ron Croonenberg said the following on 11/29/2007 3:10 AM:
>
[quoted text clipped - 27 lines]
> var serverTime = <?php echo time() ?>;
> someFunctionInThePageToDoSomethingWithTheTimeVariable();
Evertjan. - 29 Nov 2007 17:40 GMT
Ron Croonenberg wrote on 29 nov 2007 in comp.lang.javascript:

>> With ASP-jscript you can do:
>
> ASP ?  that's a windows thing...  right ?

ASP allows serverside j[ava]script

>> <script language='jscript' runat='server'>
>> response.write(new Date());
[quoted text clipped - 7 lines]
> those things that you can find in the document root  of for example an
> apache server ?

I wouldn't know, I asked you.

>> Why one line? Is this a school assignment?
>
> Uhm no...   but I can have a php script report the time, so if I can
> request a "html doc"  than i can read that script's output and get the
> time that way.

php is off topic on this NG. Please aske in a php NG.

And why one line?

Signature

Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Ron Croonenberg - 30 Nov 2007 00:47 GMT
>> ASP ?  that's a windows thing...  right ?
>
> ASP allows serverside j[ava]script

I was kidding, I know what ASP is. We're running *nix boxes though, and
we don't really need asp.

>>> <script language='jscript' runat='server'>
>>> response.write(new Date());
[quoted text clipped - 16 lines]
>
> And why one line?
Dr J R Stockton - 29 Nov 2007 19:56 GMT
>does anyone know of a simple script to get the date and time on the
>server an html document is served from ? (or a simple script to read an
>html doc that only has one line in the body section ?)

In my experience, ordinary servers cannot be trusted to get the date and
time right to within a reasonable accuracy.

Use instead a site which has a special interest in displaying date and
time.

A server should of course give the UTC date and time.  Server local date
and time do not necessarily match either that of the end user or that of
the owner of the site - particularly in the larger countries.

Signature

(c) John Stockton, Surrey, UK.  ?@merlyn.demon.co.uk   Turnpike v6.05   IE 6.
Web  <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Ron Croonenberg - 30 Nov 2007 00:45 GMT
> In my experience, ordinary servers cannot be trusted to get the date and
> time right to within a reasonable accuracy.

Oh, the ones I use can be trusted, they run all run ntp and are sync-ed
with a stratum 0 server.

> Use instead a site which has a special interest in displaying date and
> time.

uhm, ok..  but I was more interested in time differences anyway..

> A server should of course give the UTC date and time.  Server local date
> and time do not necessarily match either that of the end user or that of
> the owner of the site - particularly in the larger countries.

correct, but I am pretty sure that the servers I work with are pretty
accurate.

Ron
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.