Monday, July 18, 2005

How to Pass Client Time (and time zone) to Server with different locale id

As we know, different locale has different way of describing Date, Time, Currency, etc. For example, French (Belgium) can describe their date in dd.mm.yyyy format. If you need to pass the client timezone information and date time information to server for logging or performance measurement purpose. You will need to use client site script(s) to accomplish these.

Here is the javascript code to get the client time zone information:

function TimezoneOffset() {

var ldNow = new Date();

var lnOffset = ldNow.getTimezoneOffset()/60; // time zone in hour

lnOffset = -lnOffset; // make it Negative. For example, PST is -8, EST is -5.

FRMLGN.tz.value = lnOffset; // assume the form name is FRMLGN and the control name is tz

}

Here is the vbscript (Javascript similar) to pass the date/time information to server in U.S. ("en-us") locale.

Original = SetLocale("en-us")

FRMLGN.ltime.value = FormatDateTime(Now()) ’the form name is FRMLGN and the control name is ltime

Something = SetLocale(Original)

The once the server receives ltime value in Request("ltime"), it is easy to process by using CDate() or other functions suitable for the current locale, which I assume is "en-us".

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home