将人性化字符串转换为date.js [英] Converting humanized strings to dates moment.js

查看:132
本文介绍了将人性化字符串转换为date.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Moment.js提供人性化和日历日期,例如:

Moment.js does humanized and calendar dates, for example:

moment().calendar()
"Today at 10:17 AM"

它获取当前日期对象并转换为日历日期,和

which gets a current date object and converts to a calendar date, and

有什么办法可以相反吗?喜欢,如果我给它今天在10:17 AM,它返回一个日期对象与今天的日期和10:17 AM作为时间?

is there any way to do that in reverse? Like if I give it "Today at 10:17 AM", it returns a date object with todays date and 10:17 AM as the time?

推荐答案

date.js可以解析人类可读取的日期:

date.js can parse human readable dates:

http://www.datejs.com/

SugarJS也可以解析自然语言日期:

SugarJS can also parse natural language dates:

http://sugarjs.com/dates

它可以处理如下事情:

one day before yesterday
2 days after monday
2 weeks from monday
a second ago
25 years from now
last wednesday

另外,请看这个相关的问题:

Also, see this related question: Is there a natural language parser for date/times in javascript?

这篇关于将人性化字符串转换为date.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆