I'm having trouble figuring out how to take a datestamp and converting it to a readable date. I've tried different methods but I seem to be missing something. I'm able to get the array, loop through the values and grab what I need, I just can't seem to convert the timestamp properly (at all really).
Here is my full code with a few notes:
<script>
var ctx = $("#ertChart").get(0).getContext("2d");
var myNewChart = new Chart(ctx);
var ert = @Html.Raw(Json.Encode(Model)); // contains [{""H":"E","consumption":0.46,"readingdatetime":"\/Date(1410678000000)\/"}]
var ertLabel = [];
var ertValue = [];
for (var i in ert) {
ertLabel.push(ert[i].formatdate('yy-mm-dd', readingdatetime)); // << this is where I've been playing with the date formatting in different ways
ertValue.push(ert[i].consumption);
}
var ertLabelString = ertLabel.join(",");
var ertValueString = ertValue.join(",");
blah
var data = {
labels: [ertLabelString],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [ertValueString]
}
]
}
new Chart(ctx).Line(data);
</script>
What I'm trying to do is take readingdatetime and convert it to a readable date in
mm-dd-yyy HH:MM format if H = E
or
HH:MM if H = I
Can anyone point me in the right direction?
Here is where the modified code blows up:
var ert = @Html.Raw(Json.Encode(Model));
var ertLabel = [];
var ertValue = [];
for (var i in ert) {
var dateString = moment(ert[i].readingdatetime).format("MM-DD-YYYY HH:mm");
ertValue.push(ert[i].consumption);
}
var ertLabelString = dateString.join(","); // << Exception property or method not valid 'Join'
var ertValueString = ertValue.join(",");