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 / MS JScript / July 2008



Tip: Looking for answers? Try searching our database.

How to get the date

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Willyam Pax - 04 Jul 2008 04:04 GMT
is there any javascript code to get the date on your server?
coz in php i just use date();
Anthony Jones - 04 Jul 2008 07:43 GMT
> is there any javascript code to get the date on your server?
> coz in php i just use date();

var dat = new Date()

Signature

Anthony Jones - MVP ASP/ASP.NET

Evertjan. - 04 Jul 2008 08:07 GMT
Anthony Jones wrote on 04 jul 2008 in microsoft.public.scripting.jscript:

>> is there any javascript code to get the date on your server?
>> coz in php i just use date();
>
> var dat = new Date()

... when using ASP-jscript.

If you want to get the date FROM your server in clientside jscript,
it would depend on the available serverside scripting languages:

var dat = new Date ('<%= new Date() %>'); // ASP-js

var dat = new Date ('<%= Date %>'); // ASP-vbs

With php I would not know.

Signature

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

Anthony Jones - 04 Jul 2008 10:48 GMT
> Anthony Jones wrote on 04 jul 2008 in microsoft.public.scripting.jscript:
>
[quoted text clipped - 11 lines]
>
> var dat = new Date ('<%= Date %>'); // ASP-vbs

Currently in UK alert(dat) tells me its the 7th April  instead of the 4th
July.  You would need to format the date into an unambigous format and the
Date constructor can parse.  Additionally you would need to consider whether
you want the time as seen in the servers time zone or the clients.

Signature

Anthony Jones - MVP ASP/ASP.NET

Evertjan. - 04 Jul 2008 14:07 GMT
Anthony Jones wrote on 04 jul 2008 in
microsoft.public.scripting.jscript:

>> Anthony Jones wrote on 04 jul 2008 in
>> microsoft.public.scripting.jscript:
[quoted text clipped - 15 lines]
> Currently in UK alert(dat) tells me its the 7th April  instead of the
> 4th July.  

The 4th of July being a States side special date, I wouldn't amaze me if
English law has forbidden this date. Could you drive to Edinburgh to try
the same?

You are right, something like this should have been done:

<% d = Date %>
var dat = new Date('<%= year(d)&"/"&month(d)&"/"&day(d) %>');
// ASP-vbs, not tested

> You would need to format the date into an unambigous format
> and the Date constructor can parse.  Additionally you would need to
> consider whether you want the time as seen in the servers time zone or
> the clients.

No, seen the OQ.
Yes, in real life.

Signature

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

Dr J R Stockton - 04 Jul 2008 23:43 GMT
In microsoft.public.scripting.jscript message <Xns9AD199BEEA823eejj99@19
4.109.133.242>, Fri, 4 Jul 2008 13:07:02, Evertjan. <exjxw.hannivoort@in
terxnl.net> posted:

><% d = Date %>
>var dat = new Date('<%= year(d)&"/"&month(d)&"/"&day(d) %>');
>// ASP-vbs, not tested

IMHO, that should set the date object to a local date with the same Y M
D as the (server's) GMT date.  ICBW.  Test it between local and GMT
midnights.

Signature

(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk  Turnpike v6.05  MIME.
Web  <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

Evertjan. - 05 Jul 2008 00:52 GMT
Dr J R Stockton wrote on 05 jul 2008 in microsoft.public.scripting.jscript:

> In microsoft.public.scripting.jscript message <Xns9AD199BEEA823eejj99@19
> 4.109.133.242>, Fri, 4 Jul 2008 13:07:02, Evertjan. <exjxw.hannivoort@in
[quoted text clipped - 7 lines]
> D as the (server's) GMT date.  ICBW.  Test it between local and GMT
> midnights.

The OP requested the date of the server, that is the local date, methinks.

==========

The server's GMT date is not available with ASP-vbs,
it is with a bit of ASP-js:

=========================================
<% 'ASP-vbs
nowGMT = DateAdd("h", timezoneOffset, Now)
%>
<script language='javascript' runat='server'>
  var timezoneOffset = new Date().getTimezoneOffset()/60;
</script>
=========================================

Signature

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

Dr J R Stockton - 04 Jul 2008 23:40 GMT
In microsoft.public.scripting.jscript message <#uRrZsb3IHA.5060@TK2MSFTN
GP02.phx.gbl>, Fri, 4 Jul 2008 10:48:21, Anthony Jones
<Ant@yadayadayada.com> posted:

>Currently in UK alert(dat) tells me its the 7th April  instead of the 4th
>July.  You would need to format the date into an unambigous format and the
>Date constructor can parse.  Additionally you would need to consider whether
>you want the time as seen in the servers time zone or the clients.

If ASP can generate the date/time as milliseconds from 1970-01-01.0 GMT,
then transmitting in that form should be safest.  Generating it *might*
only need a unary +.  JScript can then give LCT or GMT.  There should
normally be no need to get server local time; the server may not even
know it.

**NO** string form is *specified* as acceptable to JavaScript new
Date(); but American will be assumed.  AFAIK, YYYY/MM/DD hh:mm:ss is
always accepted, with/without GMT/UTC.  Local designators such as EDT
are not always known; eschew.  In Nome, I suspect they think BST is
Bering Summer time; in Copacabana, Brazil Standard Time.

Signature

(c) John Stockton, nr London, UK.    ?@merlyn.demon.co.uk     Turnpike v6.05.
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.

Anthony Jones - 05 Jul 2008 12:59 GMT
> In microsoft.public.scripting.jscript message <#uRrZsb3IHA.5060@TK2MSFTN
> GP02.phx.gbl>, Fri, 4 Jul 2008 10:48:21, Anthony Jones
[quoted text clipped - 10 lines]
> normally be no need to get server local time; the server may not even
> know it.

Well I can convert the Servers local time to ms from 1970-01-01 GMT:-

Dim msPerDay: msPerDay = 1000 * 60 * 60 * 24
Dim msOffset: msOffset = 2209161600000

Dim msForJS: msForJS = (Now * msPerDay) - msOffset

However that will include an offset for daylight savings and the timeszone
offset.

There is no pure VBScript way I can think of to determine the current offset
in effect in order to restore the figure to GMT.

Of course one could always deal with this stuff using JScript server side.

> **NO** string form is *specified* as acceptable to JavaScript new
> Date(); but American will be assumed.  AFAIK, YYYY/MM/DD hh:mm:ss is
> always accepted, with/without GMT/UTC.  Local designators such as EDT
> are not always known; eschew.  In Nome, I suspect they think BST is
> Bering Summer time; in Copacabana, Brazil Standard Time.

This a string format the JScript can parse.

Jan 1 00:00:00 UTC+0000 1970

Is the month name culture specific or is english abbreviations always
acceptable and unambiguous?

Signature

Anthony Jones - MVP ASP/ASP.NET

Anthony Jones - 05 Jul 2008 13:25 GMT
> > In microsoft.public.scripting.jscript message <#uRrZsb3IHA.5060@TK2MSFTN
> > GP02.phx.gbl>, Fri, 4 Jul 2008 10:48:21, Anthony Jones
[quoted text clipped - 25 lines]
> There is no pure VBScript way I can think of to determine the current offset
> in effect in order to restore the figure to GMT.

This is close but I think using JScript may be a better alternative and it
would need to cache the found timebias in order to be effecient.

Function GetNowUTC()

Dim msPerDay: msPerDay = 1000 * 60 * 60 * 24

Dim oShell: Set oShell = CreateObject("WScript.Shell")
Dim msOffset

msOffset =
oShell.RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZone
Information\ActiveTimeBias")
msOffset = 2209161600000 - msOffset * 60 * 1000

GetNowUTC = (Now * msPerDay) - msOffset

End Function

...

<script type="text/javascript">

var serverTime = new Date(<%=GetNowUTC%>);

Signature

Anthony Jones - MVP ASP/ASP.NET

 
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



©2008 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.