So this is my code:
var input = '2015-07-13T22:00:00Z';
var output = encodeURIComponent(input);
console.log(output);
How can i use encodeURIComponent
in momentjs?
Thanks.
So this is my code:
var input = '2015-07-13T22:00:00Z';
var output = encodeURIComponent(input);
console.log(output);
How can i use encodeURIComponent
in momentjs?
Thanks.
It encodes the URI of the component so that it can be accessed easily.
For example -
becomes
https%3A%2F%2Fwww.google.com%3Fmyquery%3Dmy%20query
after using encodeURIComponent()
But if you need to change the format of your date, you should use .format() method.
It could make some sense using JS encodeURIComponent() function on an ISO 8601 date only if you need to use that value as an URL parameter, passing it 'as-is' for example to a REST endpoint...
UPDATE 1:
You could use it, for example, this way:
var input = '2015-07-13T22:00:00Z';
var output = encodeURIComponent(input);
var endpoint = 'https://example.com/endpoint/date=' + output;
UPDATE 2:*
Or, this way:
var input = moment().toISOString();
var output = encodeURIComponent(input);
var endpoint = 'https://example.com/endpoint/date=' + output;
...