[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3300
  • Last Modified:

Regional Settings with VBScript or Javascript

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
nalwine
Asked:
nalwine
  • 3
  • 2
1 Solution
 
frugleCommented:
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
 
nalwineAuthor Commented:
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
 
frugleCommented:
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
 
nalwineAuthor Commented:
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
 
nalwineAuthor Commented:
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now