是否有任何JavaScript日期选择器允许我们选择“昨天”,“明天”,“下周”等人类语言日期而不是实际日期?带有像昨天,明天而不是日期的字符串的日期选择器
事实上,任何客户端库会给我们这个功能将是有用的。
是否有任何JavaScript日期选择器允许我们选择“昨天”,“明天”,“下周”等人类语言日期而不是实际日期?带有像昨天,明天而不是日期的字符串的日期选择器
事实上,任何客户端库会给我们这个功能将是有用的。
我能够结合使用dateJs与moment.js到相当好听达到这种效果(只针对英语作为工作是,其他语言,你需要包括appropriate globalization file):
$('#smartdatepicker').blur(function() {
// parse date from string
var mydate = Date.parse($(this).val());
// create a moment from that and format it however we want
var myMoment = moment(Date.parse($(this).val())).format('L')
// set converted value to input
$(this).val(myMoment);
// below does the above in one line
//$(this).val(moment(Date.parse($(this).val())).format('L'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
<input type="text" id="smartdatepicker" />
<br>
<br>Type something into the box then click away from it
<br>
<br>
<br>Examlples:
<br>
<br>Friday
<br>Next Friday
<br>Last Year
<br>
似乎是我在找的东西!谢谢! – Arunster
您可以使用DateJs。从文档
摘录:
解析下面的列表是只有几百 字符串格式,它可以正确解析不提供日期 格式的一小部分。所有解析都通过包含适当的 CultureInfo文件完全全球化。 CultureInfo文件包含用于解析和格式化的所有字符串 。
所有CultureInfo文件都可以在
/trunk/source/globalization/
文件夹中找到。以下
.parse()
示例使用en-US.js CultureInfo文件。
Date.parse('t') // Returns today's date.
Date.parse('today') // Returns today's date.
Date.parse('tomorrow') // Returns tomorrow's date.
Date.parse('yesterday') // Returns yesterday's date.
Date.parse('next friday') // Returns the date of the next Friday.
Date.parse('last monday') // Returns the date of the previous Monday.
Date.parse('July 8th, 2004') // Thu Jul 08 2004
Date.parse('15-Jan-2004') // Thu Jan 15 2004
Date.parse('7/1/2004') // Thu Jul 01 2004
Date.parse('7.1.2004') // Thu Jul 01 2004
Date.parse('07.15.04') // Thu Jul 15 2004
Date.parse('July 23rd 2004') // Fri Jul 23 2004
Date.parse('Sat July 3, 2004') // Sat Jul 03 2004
Date.parse('10:30 PM EST') // Wed Oct 31 2007 20:30:00
Date.parse('10PM') // Wed Oct 31 2007 22:00:00
Date.parse('t + 5d') // Adds 5 days to today.
Date.parse('today - 1 month') // Subtracts 1 month from today.
Date.parse('+') // Add 1 day to today = tomorrow.
Date.parse('- 3months') // Subtract 3 months.
Date.parse('+1year') // Add a year to today.
Date.parse('-12 months') // Subtract 12 months (1 year) from today.
Date.parse('July 4th') // July 4th of this year.
Date.parse('15') // 15th day of current month/year.
Date.parse('July 8th, 2004, 10:30 PM') // Thu Jul 08 2004 22:30:00
Date.parse('2004-07-15T06:45:00') // Thu Jul 15 2004 06:45:00
Date.parse('Thu, 1 July 2004 22:30:00 GMT') // Thu Jul 01 2004 16:30:00
Date.parse('1997-07-16T19:20:15') // ISO 8601 Formats
Date.parse('1997-07-16T19:20:30+01:00') // ISO 8601 with Timezone offset
Date.parse('1985-04-12T23:20:50Z') // RFC 3339 Formats
我不知道日期选择器库,但你可以日期manipulatio检查出[MomentJS(http://momentjs.com/) ñ。您可以自定义它根据自己的需要:) –
http://stackoverflow.com/questions/19025330/get-tomorrows-date-with-jquery-and-compare 这可能是有用的.. –
@Hayat,答案链接似乎已经死了。 – Arunster