Is there a natural language parser for date/times in javascript?

前端 未结 5 2001
抹茶落季
抹茶落季 2020-12-03 10:16

Is there a natural language parser for date/times in javascript?

相关标签:
5条回答
  • 2020-12-03 10:35

    Does Date.js satisfy your needs? Or are you looking for something else?

    0 讨论(0)
  • 2020-12-03 10:37

    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.

    0 讨论(0)
  • 2020-12-03 10:39

    For node, I've found chrono to work well

    Chrono supports most date and time formats, such as :

    • Today, Tomorrow, Yesterday, Last Friday, etc
    • 17 August 2013 - 19 August 2013
    • This Friday from 13:00 - 16.00
    • 5 days ago
    • 2 weeks from now
    • Sat Aug 17 2013 18:40:39 GMT+0900 (JST)
    • 2014-11-30T08:15:30-05:30
    0 讨论(0)
  • 2020-12-03 10:43

    You can use the jQuery datepicker translation, get the day and month number and select the day from datepicker days.

    You can add values to this object, and you can download up to 60 languages I think. (The object below is not complete, I removed some code to simplify it).

    $.datepicker.regional['sv'] = { 
      monthNames:['Januari','Februari','Mars','April','Maj','Juni','Juli','Augusti','September','Oktober','November','December'],
      monthNamesShort: ['Jan','Feb','Mar','Apr','Maj','Jun','Jul','Aug','Sep','Okt','Nov','Dec'],
      dayNamesShort: ['Sön','Mån','Tis','Ons','Tor','Fre','Lör'],
      dayNames: ['Söndag','Måndag','Tisdag','Onsdag','Torsdag','Fredag','Lördag'],
      dayNamesMin: ['Sö','Må','Ti','On','To','Fr','Lö']
    };
    

    Now get the day and month number

    var dateObject = new Date();
    var day = dateObject.getDay();
    var month = dateObject.getMonth();
    var monthText = $.datepicker.regional['sv']['monthNames'][month];
    var dayText = $.datepicker.regional['sv']['dayNames'][day];
    
    0 讨论(0)
  • 2020-12-03 10:47

    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') .

    0 讨论(0)
提交回复
热议问题