I have got a text box where the user enters a date, for example for the 20th of Jan - my American users will enter '1/20/2009' and my Australian users will enter '20/1/2009'. How can I parse these different string formats into the same javascript Date object
so I can work with it on the client? Can I use the microsoft AJAX library with MVC (asp:ScriptManager EnableScriptGlobalization="true")?
I worked it out. I can use Microsoft AJAX library with globalisation support, however as it is a MVC application I can't use the asp:ScriptResource tags.
you can then use the date format functions in the microsoft AJAX library to do string to date conversions and date to string based on the user's locale.
Marked as answer by tysonkb on Oct 15, 2009 02:19 PM
tysonkb
0 Points
4 Posts
Parsing a string into javascript date object based on locale
Oct 14, 2009 06:59 AM|LINK
Hi,
I have got a text box where the user enters a date, for example for the 20th of Jan - my American users will enter '1/20/2009' and my Australian users will enter '20/1/2009'. How can I parse these different string formats into the same javascript Date object so I can work with it on the client? Can I use the microsoft AJAX library with MVC (asp:ScriptManager EnableScriptGlobalization="true")?
Thanks!
KeFang Chen ...
Star
8329 Points
852 Posts
Re: Parsing a string into javascript date object based on locale
Oct 15, 2009 10:03 AM|LINK
Hi,
Maybe you can take a look at the following code. But firstly you need to download the jquery-ui-1.7.2.custom.min.js from Jquery.
Firstly we need to import 2 scripts and a css file.
<link href="../../css/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" /> <script src="../../Scripts/jquery-1.3.2.min.js" type="text/javascript"></script> <script src="../../Scripts/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>Then
<script type="text/javascript" language="javascript"> $(document).ready(function() { $('#DateReleased').datepicker({ duration: '', showTime: true, constrainInput: false }); } ) </script> <label for="DateReleased">DateReleased:</label> <%= Html.TextBox("DateReleased",null, ViewData["Readonly"] as IDictionary<string, object>)%>Dictionary<string, object> ID = new Dictionary<string, object>(); ID.Add("readonly", "readonly"); ViewData["Readonly"] = ID;tysonkb
0 Points
4 Posts
Re: Parsing a string into javascript date object based on locale
Oct 15, 2009 02:18 PM|LINK
I worked it out. I can use Microsoft AJAX library with globalisation support, however as it is a MVC application I can't use the asp:ScriptResource tags.
I found this post:
http://stackoverflow.com/questions/817046/what-about-script-globalization-of-microsoftajax-js-in-asp-net-mvc
you can then use the date format functions in the microsoft AJAX library to do string to date conversions and date to string based on the user's locale.