|
Locale-aware formating component - freeLast updated: 11/18/98, Initial Release A new feature introduced with IIS4 is the Session.LCID property, which allows you to set a specific LCID for the pages - settings that are the picked up by functions like FormatCurrency, FormatDateTime and Monthname (list not meant to be complete). Being not really satisfied with the functions provided (and having experienced some side-effects) by Session.LCID, I had a formatting component on my list of things to do for quite a while - now I got around doing it. Because I think that it would be interesting for you to see what is going on behind the scenes of such a formatting component (and IIS won't implement it in a very different manner...), I decided to clean up my source code and provide it also for FREE (this means you can use the component and the source code for FREE). You can find the documentation for the component here. The source code for the component, the compiled component (VC6/SP1, mulithreaded, statically linked) and documentation plus sample script here 100 KB. The component and source code are free, however, the risk of using it is also yours! You can find more information about locales in our article about Session.LCID Here is the code of the sample ASP page that comes with the component: <% ' create the object dim LangObj set LangObj = Server.CreateObject("Softwing.LocaleFormatter") ' set the LCID - see the include file for constants relevant to your ' target audience; here we are using German/Austrian (my preference) dim nLang nLang = MAKELCID(MAKELANGID(LANG_GERMAN, _ SUBLANG_GERMAN_AUSTRIAN),SORT_DEFAULT) ' First, test the date related function Response.Write "Simple date formatting: " & _ LangObj.FormatDate(Now(), nLang) & "<BR>" Response.Write "Date formatting using picture: " & _ LangObj.FormatDatePicture(Now(),"ddd',' MMM dd yy", nLang) & "<BR>" ' next, we use the time functions... Response.Write "Simple time formatting: " & _ LangObj.FormatTime(Now(), nLang) & "<BR>" Response.Write "Time formatting using pictures: " & _ LangObj.FormatTimePicture(Now(),"hh':'mm':'ss tt", nLang) & "<BR>" ' combined date & time functionality Response.Write "Combined date/time formatting: " & _ LangObj.FormatDateTime(Now(), nLang) & "<BR>" ' get the month name Response.Write "Long Monthname: " & _ LangObj.Monthname(Month(Now()), nLang, False) & "<BR>" Response.Write "Short Monthname: " & _ LangObj.Monthname(Month(Now()), nLang, True) & "<BR>" ' get the weekdayname, based on same functionality as found ' for the Weekdayname function in VBScript Response.Write "Long Weekdayname: " & _ LangObj.Weekdayname(Weekday(Now()), nLang, False, 0) & "<BR>" Response.Write "Short Weekdayname: " & _ LangObj.Weekdayname(Weekday(Now()), nLang, True, 0) & "<BR>" ' Format a currency string Response.Write "Money formatting: " & _ LangObj.FormatCurrency(23.56,nLang) & "<BR>" ' format a generic number according to settings Response.Write "Number formatting: " & _ LangObj.FormatNumber(12223.56,nLang) & "<BR>" %> If you do have any questions, please feel free to send mail to Christoph Wille. |
All content and images on this site are copyright. Reuse (even parts) needs our written consent. |