CellFilter Date Format
How do I form the date time with the cell filter? I found samples of date only, but I need a bit of help formatting it.
http://plnkr.co/edit/HiCt52ntdWDHtgXN8x0A?p=preview
"2015-02-03T05:49:54.850Z" to 2015-02-03 5:49 AM OR "2015-02-02T17:09:37.790Z" to 2015-02-02 17:09
- Date with filter converts the time automatically to GMT-0. Why?
- How do I format the cell filter so that it keeps it in the same timezone?
- Also, how about the AM and PM?
The filter is the standard angularJS date filter, and behaves in the same way as that filter. I suspect the time format is driven by your browser. Refer https://docs.angularjs.org/api/ng/filter/date
Oh! Okay. Thanks for the link and quick response.
I had to use moment.timezone.js to get it to work :)
@redapplewithleaves, how did you get this to work?
When using ng-grid I cannot override the system time zone with date:'2015-02-03T05:49:54.850Z':'-0600'
I made helper functions that takes in the value using moment.js (http://momentjs.com/)
function formatDateTime(value) {
if (value) {
var v = moment(value).format('YYYY-MM-DD');
//default null value for my db
if (v == "12-31-1899") {
return "";
} else {
return v;
}
}
return "";
}
I called that function in a for-loop or set it up in model of the object. Then just used the return values to display it to the grid.

With moments.js its easier to override the timezone.
thanks, I will try that.
So just to confirm, you did experience trouble with supplying a timezone when using cellFilter in colDefs or even date filter within a custom cellTemplate?
When I use either method, I can never override the timezone. Is this a known issue with ng-grid? For example: {{row.getProperty(col.field) | date:'yyyy-MM-dd HH:mm:ss Z':'-0800'}}, does not change the time zone to -0800, but would still use the system/browser timezone. Or am I using incorrect syntax?
Thanks.
This is still a known issue. It would be possible to use moment as suggested earlier, but that solves the date format issue, which I don't seem to have a problem with if inserted this way:
{
displayName: 'Some Date',
field: 'fieldfromdb',
cellFilter: 'date : \'MM-DD-YYYY\'',
}`
However, what seems like an easy implementation of timezone in the ui-grid's gridOptions object (in the same fieldfromdb object) doesn't seem to be working:
{
displayName: 'Some Date',
field: 'fieldfromdb',
cellFilter: 'date : \'MM-DD-YYYY\' : \'UTC\'',
}
Any updates on this issue?
I am having the same issue, I am able to resolve this issue in other ways like using JavaScript functions but I want to convert my date in CellFilter, not just UTC, it should pick the browser timezone. It will be helpful for short coding.
Thanks
But if the date value is unix seconds rather than milliseconds, how to fix this?