Solved

Regional Settings with VBScript or Javascript

Posted on 2004-09-03
5
3,275 Views
Last Modified: 2012-08-13
I have an XSL Template that gets XML data in English Regional Settings.  However, I need to be able to convert my numbers into whatever regional format is specified by the browser.  Dates were pretty simple to accomplish this.  How do I do numbers?  Is there a function that I can pass in a number and tell the function that this number is in English regional settings, and have that function return the number in my desired format?

Thanks
Nate
0
Comment
Question by:nalwine
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:frugle
ID: 11975985
Session.LCID = 2057

will set an English (British) Locale, I guess you just need to get the browser language and compare with a list of locales.

Response.Write FormatNumber(num, 2, -2) 'Formats the number (num) with 2x decimal points and uses the default locale.

a good list of LCID can be found at http://www.juicystudio.com/tutorial/asp/lcid.asp

Mike
0
 

Author Comment

by:nalwine
ID: 11977632
ok,

this does what I want:

var localval = new Number("<xsl:value-of select="DecimalParameterValue" />");
Production.actual = localval.toLocaleString();

But!!!!  I was wrong about my dates.  I was doing a dateformat, but it turns out dateformat was just taking my english date and treating it as already regional format.  (ie, it looked right but it wasn't)  

So I will award these points to whoever can answer this question:
How do I take an American Date (8/31/2004 13:00:00) and convert it to its proper regional format eg if the browser is set to German--(31.8.2004 13:00:00)?

toLocaleString will not work because it has to be just numbers no words.

nate
0
 
LVL 10

Accepted Solution

by:
frugle earned 500 total points
ID: 11978080
What is the effect of adding:

<% Session.LCID = 1031 %>

to the top of your script?

am I barking completely up the wrong tree with LCID?

from MSDN: The LCID refers to how dates, times, and currency are formatted for a specific geographical locale.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/ref_vbom_sesoplcid.asp

Mike
0
 

Author Comment

by:nalwine
ID: 11995533
Unfortunately I am not working with ASP in this instance.  So I don't believe it is possible to do what you're saying.  However, I was able to get the numbers to be formatted the way I was wanted by the javascript I included above.

So that being said, here is my final issue with this page.  This is actually a XML Page being transformed by an XSL Template.  In the XML I have two dates, each in the following format: mm/dd/yyyy hh:nn:ss       I can split these apart to get the month, day, and year very easily.  But I need to know either a)how to reconstruct it according to short date format as specified in the regional settings.  or b)Pass the month, day, and year into some sort of javascript or vbscript object and be able to print the date to the page in the short date format as specified by regional settings.

any ideas?

thanks
0
 

Author Comment

by:nalwine
ID: 11996218
ok, this issue has been solved and I will award to points to frugle, however this was the solution I came up with:

Step 1)

Create the following VBScript Function:
<script language="vbscript">
Function FormatDateString(year, month, day, time)
  Dim strDate, retstring
  strDate = DateSerial(year,month,day)
  retstring = FormatDateTime(strDate, 2) + " " + time
  FormatDateString = retstring
End Function
</script>      



Step 2)

In my javascript I did the following:


var StartTime = "<xsl:value-of select="Value" />";
var myArray = StartTime.split('/');
var month = myArray[0];
var day = myArray[1];
var year = myArray[2];
myArray = year.split(' ');
year = myArray[0];
var time = myArray[1] + ' ' + myArray[2];
var dStartTime = FormatDateString(year, month, day, time);
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question