Is there a natural language parser for date/times in javascript?
Does Date.js satisfy your needs? Or are you looking for something else?
SugarJS supports some natural language parsing of dates and times.
You can jump to the live example here: http://sugarjs.com/dates
For example, it supports the following inputs:
- the day after tomorrow
- 2 weeks from monday
- May 25th of next year
You can then covert the result into different date formats or use the API to further manipulate the date.
Chrono v2 is the only library I've found that also parses timezones.
Unfortunately, the only documented way of using it is via NPM (npm i chrono-node
) or as ES6 Module (import * as chrono from 'chrono-node'
), but I found a way to use the library with the traditional script tag approach for those interested.
Non-NPM / non-module usage:
- Include this script: https://www.unpkg.com/chrono-node/dist/bundle.js
- Use the global variable
chrono
in your script (available methods here)
E.g. chrono.parseDate('Tomorrow at 4 PM PST')
⚠ Note: I have not tested this extensively, so don't expect it to work flawlessly
I made Chrono a small library for parsing dates in JavaScript. I added a date range parsing feature (such as '12 Nov - 13 Dec 2012') .