开发者

is there any way to parse date in string using Datejs?

开发者 https://www.devze.com 2023-03-05 06:21 出处:网络
I came across Datejs recently and开发者_开发百科 found it very useful. However I could not figure out if there is a way to parse a string and extract only date part from it using the same.

I came across Datejs recently and开发者_开发百科 found it very useful. However I could not figure out if there is a way to parse a string and extract only date part from it using the same.

For example, if there is a string >> "I will start exercise from next Monday."

Then it should parse the string, extract 'next monday' from it and convert it into date and give me the result.

How can it be implemented?

Thanks :)


You can write some RegEx for that. That would be the easiest way. 'next' will be a keyword in that case. A simple function can lookup the current weekday and return the date of the next monday. Should not that complicated.

Edit:

You can do something like this:

var pattern = /^([\w\W.]*)(next){1}([\sa-zA-Z]*)/;
while (result = pattern.exec(yourTextVariable) != null){
   // read the data as you need from the result array
}

The Pattern above expecting a white space then the keyword next and will red the next word if it only has alpha-letters. (please note that the RegEx is untested and may need some refactoring to fit your needs. You may take a look at this page to do this: javascriptkit.com)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号