dalemac
dalemac

Reputation: 464

jQuery.jgrid.parseDate date formatting

I have searched for this but couldn't find anyone trying to do what i am doing with jqGrid formatters.

I have a date which I am trying to parse which is not in a jqGrid table, but I am using jqGrid on the site elsewhere and am hoping to parse this date using jqGrid's date parser instead of having to write a seperate method.

I have been messing around with the jGrid object but I need a little help with this.

My date format is ISO8601Long i.e. 2013-11-17T09:00:00

First, I am ensuring the date formats in the formatter are the ones i wish to use:

jQuery.jgrid.formatter.date.srcformat = 'Y-m-d H:i:s';
jQuery.jgrid.formatter.date.newformat = 'j/m/Y g.ia';

Next, I call the jQuery.jgrid.parseDate method in an attempt to parse the date.

jQuery.jgrid.parseDate(0, 0, '2013-11-17T09:00:00');

I am not sure what the first two arguments are, but they look like they might accept a srcformat and newformat. Either way, they don't format as I would expect. There is a fourth too, but this seems to only accept an object.

This leaves me with 2013-11-17GMT09:00:00. While this is a bit easier to understand, it is not in the format I would be expecting. I presume I have missed a step or somehow need to call the formatter after this.

Any pointers would be great.

Thanks,

Dale

Upvotes: 2

Views: 1078

Answers (1)

Oleg
Oleg

Reputation: 221997

The correct usage of parseDate would be the following:

var parsedData = $.jgrid.parseDate("Y-m-d H:i:s", "2013-11-17T09:00:00", "j/m/Y g.ia");

or

var parsedData = $.jgrid.parseDate("ISO8601Long", "2013-11-17T09:00:00", "j/m/Y g.ia");

You can use alternatively Globalize jQuery Plugin.

Upvotes: 2

Related Questions