简体   繁体   English

JS-独立的用户输入日期解释器

[英]JS - standalone user-input date interpreter

I've spent literal hours searching the web for a JS library or a Node module that does just one thing: interpret user-input dates of all kinds (just english is fine) and converts them to a standard date. 我花了数小时在网上搜索仅做一件事的JS库或Node模块:解释各种用户输入的日期(仅英语即可)并将它们转换为标准日期。

For example, it should be able to recognize and convert the following into actual dates: 例如,它应该能够识别以下内容并将其转换为实际日期:

tomorrow 
in a year
last week
in 8 hours
in 4 months
8 8 90
65

Sugar.js does this, however I don't want all its other features, and it extends native objects. Sugar.js做到了这一点,但是我不想要其所有其他功能,它扩展了本机对象。 Moment.js deprecated its ability to do this as they consider it too opinionated - fine. Moment.js弃用了执行此操作的能力,因为他们认为这样做太自以为是-很好。

One would think someone made a library for this. 有人会认为有人为此做了一个图书馆。 Does anyone know of any? 有人知道吗?

In cases like this where a library provides a functionality that I need but I do not need the entire library, I will just strip out the portion of the library that I need. 在这种情况下,如果某个库提供了我需要的功能,但我不需要整个库,那么我将只去除我需要的库的一部分。

Sugar.js actually provided a customize option, so this is even easier to do. Sugar.js实际上提供了一个自定义选项,因此更容易做到。

http://sugarjs.com/customize http://sugarjs.com/customize

Additionally if you use bower or npm for your package management, there is already a package that just has the Date functions from Sugar.js: 另外,如果您使用bower或npm进行程序包管理,则已经有一个程序包具有Sugar.js中的Date函数:

https://github.com/fiznool/sugar-date https://github.com/fiznool/sugar-date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM