window.grid = new (declare([Grid, Selection])) ({ bufferRows:Infinity, columns: { "id": "ID", "vehicleId": "Vehicle ID", "velocity": {"label": "Speed (MPH)", "formatter":dojoNum.format}, "timestamp": {"label": "Time Stamp", "formatter":dojo.date.locale.format} } }, "grid");
Solved! Go to Solution.
window.grid = new (declare([Grid, Selection])) ({ bufferRows:Infinity, columns: { "id": "ID", "vehicleId": "Vehicle ID", "velocity": {"label": "Speed (MPH)", "formatter":dojoNum.format}, "timestamp": {"label": "Time Stamp", "formatter":formatTimestamp} } }, "grid"); . . . . function formatTimestamp(value) { var inputDate = new Date(value); return dojo.date.locale.format(inputDate, { selector: 'date', datePattern: 'MM/dd/yyyy' }); }
Hi Michelle,
The date value you mentioned is epoch time,which is defined as the number of seconds since midnight (UTC) on 1st January 1970.
What is epoch time?
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking the epoch is Unix time 0 (midnight 1/1/1970), but 'epoch' is often used as a synonym for 'Unix time'. Many Unix systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038).
Human readable time Seconds
1 hour 3600 seconds
1 day 86400 seconds
1 week 604800 seconds
1 month (30.44 days) 2629743 seconds
1 year (365.24 days) 31556926 seconds
Although when you are retrieving the value and want to display in your application you will have to convert it using the below:
var someDate = new Date(dateString);
Hope this helps.
Best Regards,
Manish Patel
window.grid = new (declare([Grid, Selection])) ({ bufferRows:Infinity, columns: { "id": "ID", "vehicleId": "Vehicle ID", "velocity": {"label": "Speed (MPH)", "formatter":dojoNum.format}, "timestamp": {"label": "Time Stamp", "formatter":formatTimestamp} } }, "grid"); . . . . function formatTimestamp(value) { var inputDate = new Date(value); return dojo.date.locale.format(inputDate, { selector: 'date', datePattern: 'MM/dd/yyyy' }); }
When I've used a formatter with my dGrids, I have it call a standalone function instead of doing the formatting work inline. Your modified code would be something like this:window.grid = new (declare([Grid, Selection])) ({ bufferRows:Infinity, columns: { "id": "ID", "vehicleId": "Vehicle ID", "velocity": {"label": "Speed (MPH)", "formatter":dojoNum.format}, "timestamp": {"label": "Time Stamp", "formatter":formatTimestamp} } }, "grid"); . . . . function formatTimestamp(value) { var inputDate = new Date(value); return dojo.date.locale.format(inputDate, { selector: 'date', datePattern: 'MM/dd/yyyy' }); }
function formatTimestamp(value) { var inputDate = new Date(value); return inputDate.toString(); }