Solved

Regional Settings with VBScript or Javascript

Posted on 2004-09-03
5
3,270 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This video teaches users how to migrate an existing Wordpress website to a new domain.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now