I am working with an array of JSON objects retrieved from my MVC controller. These objects contain date fields that I need to parse and format.
By using the Newtonsoft.Json library in place of the default MVC JSON serialiser, my dates are already formatted nicely when they come back like this:
"SystemDate": "2013-05-06T17:19:40.443",
"LocalDate": "2013-05-06T18:19:40",
To handle these dates on the client side, I am utilizing Moment.js for date manipulation. I've been exploring ways to further format these dates for display purposes.
Instead of creating a custom function, which would take a JSON array of objects with dates to format along with specific field names and a date pattern, I'm considering if there is a built-in functionality in Moment.js that might achieve this more efficiently.
The proposed function signature would resemble something like:
function formatDates(dataArray, pattern, fields) { /code/ };
The dataArray structure could be similar to:
[{"name": Jammer,
"SystemDate": "2013-05-06T17:19:40.443",
"LocalDate": "2013-05-06T18:19:40"
},
{another object}
{another object}
{another object}
]
A sample pattern might look like:
"dddd, MMMM Do YYYY, h:mm:ss a"
And the list of fields would be (using the provided example object):
[{"SystemDate"}, {"LocalDate"}]
While I am still relatively new to Moment.js and its API, I have not found any existing functionality within it that caters to this specific requirement after reviewing the documentation.
Before proceeding with implementing my custom function, I wanted to inquire if there are any features in Moment.js that could potentially streamline this process or if there are any suggestions on the best approach to accomplish this task?