Click here to Skip to main content
15,888,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a website coded in VB-Script and need to show the Dates (Short-Date) in a format as per the Client machine configuration.
For Example if a client machine is configured to English(UK) format and short date is set as d.M.yy then the system date is shown as 13.10.16. So I want that my website also shows the date in this format.

Kindly suggest me some way to get this done.

Thanks

What I have tried:

I know this could not be done in server side code as it will return the server style formatted date and thus tried a javascript function .toLocaleDateString() but unfortunately this returns a date in long format and I need a date in short format.
Posted
Updated 13-Oct-16 4:38am

1 solution

See JavaScript Date Reference[^]. Those are all the ways to get your dates in JavaScript.

Note, you could it on the server if needed by changing the thread UI, for example, and then generating the date.
 
Share this answer
 
Comments
NK Sharma 14-Oct-16 9:18am    
Thanks for your reply Ryan. I had already checked all methods in the link provided but none of them worked for me.

You had mentioned that the client date-format can also be get at server side code, so can you provide any example for that?
NK Sharma 17-Oct-16 9:03am    
Let me give it a try.
NK Sharma 8-Nov-16 5:11am    
Thanks for your suggestion Ryan and sorry for a late reply.

I gave it a try but my bad luck that nothing works for me. I follow many other such threads and try all suggested options but finally conclude that by using either server-side or client-side code, only the client's selected Date-Format (like English(UK), English(US), English(Canada) etc.) can be get with their default selection of Short-Date-Formats (like 'dd/MM/yyyy', 'M/d/yyyy', 'yyyy-MM-dd' for UK, US, Canada respectively). In other words any custom selection of Short-Date-Format on client machine cannot be get, rather only the default selection can be get.

Server Side---
Request.UserLanguages[0]

Client Side---
navigator.userLanguage

Once we get the client's selected date format language then a specific culture can be set to the current thread. Which will return a date in default format automatically.

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0])

Naresh

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900