I am working with a JSON array string pulled from a database and I need to format the DateAndTime field into yyyy-MM-dd hh:mm:ss. This formatting needs to be flexible as the data passed through will vary, except for the DateAndTime.
Here is my current attempt:
ASPX
var chartData = <%= DataToJSONChart() %>;
var new_data = []
for (var i = 0; i < chartData.length; i++) {
var date = new Date(parseInt(chartData[i].DateAndTime.substr(6)));
new_data.push(date);
}
chartData.tblGeneral = new_data;
VB
Public Function DataToJSONChart() As String
Dim dt As DataTable
Dim ds As New DataSet()
ds = ChartData(4, DateTime.Parse("2012-06-01 00:00:00"), DateTime.Parse("2012-06-10 23:59:59"))
dt = ds.Tables(0)
Dim serializer As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer()
Dim rows As New List(Of Dictionary(Of String, Object))
Dim row As Dictionary(Of String, Object)
For Each dr As DataRow In dt.Rows
row = New Dictionary(Of String, Object)
For Each col As DataColumn In dt.Columns
row.Add(col.ColumnName, dr(col))
Next
rows.Add(row)
Next
serializer.MaxJsonLength = Int32.MaxValue
Return serializer.Serialize(rows)
End Function