Is there a javascript library or some other mechanism that will allow me to pass a .NET date/ time format string (i.e., yyyy-MM-dd HH:mm:ss
) to a javascript function and have it parse a supplied datetime value accordingly? I've been looking for a while but I can't seem to find exactly what I am looking for.
My imagined usage will allow me to provide a custom format string from a .NET provider, and allow my existing javascript libraries (like Kendo) to render the date/time consistently.
Since there seem to be some confusion about what I am asking, I will try to be more detailed:
I have a User Preferences
table that allows my users to choose the format of their dates, their timestamps, and their times, among other things, and it is completely customizable using .NET string formatting. Rendering these is easy from my .NET application.
However, I am also using Kendo, and it will collect raw date/time data from my server; I need to have the data it renders formatted consistently between the javascript library and the .NET rendering engine.
So the short answer seems to be, there is not a means to standardize date formats, so... I wrote one. There are several limitations with this little library; for example, I'm completely ignoring time zones (all my work is UTC anyway) and I am not checking for escaped special characters, but it should do for my purposes:
You can use it like so:
Improvements are welcome.
momentjs has worked well with dealing with dates in javascript for us. It should fit both your needs.
UPDATE: momentjs will allow you to use your own formatting string 'MM-DD-YYYY' or any variation thereof to display the date.
If you can in your .NET application, when you convert the DateTime object to a string do it like this:
That way you won't have to worry about locale based differences on date time strings and most languages should be able to handle this format without a problem