Question

I have a textbox where input can be like--> "2 days ago","1 month ago" based on above input I need a date value. I could not find the suitable method for it in Momentjs

Était-ce utile?

La solution

You know moment.js provides such type of functionality, for example:

var sd = new moment("April 15, 2000");
sd.add('years', 13);
sd.add('m', 3);
sd.subtract('days',14);

But in your case you must parse your input text, and in different cases use different functions from moment.js

Autres conseils

Found a similar javascript function. But I haven't tried it myself. Please see if this helps.

http://phpjs.org/functions/strtotime/

What you're looking for is a library that parses relative dates.

Try http://www.datejs.com/

On the main page there's an example where you can enter text (like "4 days ago") and it shows you how it is parsed using their library.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top