Conson
June 3rd, 2005, 04:15 AM
Hello Gurus!
I need to convert some client-side VBScript into Javascript.
In the VBScipt a date is converted from a weird format into the format that the user have set up on the client browser.
This is easily done by splitting the weird string into pieces and putting it back together with FormatDateTime.
I have created the Javascript to do the same BUT the problem is that I can only manage to get the long format of the date. I want the short!..
The VBScript function creates the short format as standard but can me set up to return the long etc.
Input looks like this "05-06-02" (yy-mm-dd).
The code looks like this:
function WDate2Date(e)
{
var timestamp, strday, strmonth, stryear, slash1, slash2, result;
result = e;
timestamp = e;
slash1 = timestamp.indexOf("-");
slash2 = timestamp.indexOf("-", slash1 + 1);
if(slash1 > -1 && slash2 > -1)
{
stryear = timestamp.substring(0, slash1);
strmonth = timestamp.substring(slash1+1, slash2);
strday = timestamp.substring(slash2+1, slash2+3);
if(parseInt(stryear) < 49)
{
stryear = parseInt(stryear) + 2000;
}
else
{
stryear = parseInt(stryear) + 1900;
}
var date = new Date(stryear, parseInt(strmonth) - 1, strday);
result = date.toLocaleString();
}
return result;
}
Have anyone got any workaround for this??
Or any other comment?
Thanks in advance!
Conson..
I need to convert some client-side VBScript into Javascript.
In the VBScipt a date is converted from a weird format into the format that the user have set up on the client browser.
This is easily done by splitting the weird string into pieces and putting it back together with FormatDateTime.
I have created the Javascript to do the same BUT the problem is that I can only manage to get the long format of the date. I want the short!..
The VBScript function creates the short format as standard but can me set up to return the long etc.
Input looks like this "05-06-02" (yy-mm-dd).
The code looks like this:
function WDate2Date(e)
{
var timestamp, strday, strmonth, stryear, slash1, slash2, result;
result = e;
timestamp = e;
slash1 = timestamp.indexOf("-");
slash2 = timestamp.indexOf("-", slash1 + 1);
if(slash1 > -1 && slash2 > -1)
{
stryear = timestamp.substring(0, slash1);
strmonth = timestamp.substring(slash1+1, slash2);
strday = timestamp.substring(slash2+1, slash2+3);
if(parseInt(stryear) < 49)
{
stryear = parseInt(stryear) + 2000;
}
else
{
stryear = parseInt(stryear) + 1900;
}
var date = new Date(stryear, parseInt(strmonth) - 1, strday);
result = date.toLocaleString();
}
return result;
}
Have anyone got any workaround for this??
Or any other comment?
Thanks in advance!
Conson..