获取诸如“明天”、“三天内”、"3个月30天“、”2011年3月30日“等用户输入,并将其解释为可由php使用的时间戳。
我觉得我以前在任务管理系统中见过这样的东西。我想用它做一些不同的东西,但我找不到任何预煮的东西。也许我在“记得牛奶”上看过?(在我写这篇文章的时候,它已经写下来了)
有没有人知道这样的事情?(最好是php)
发布于 2010-08-08 15:46:01
看一看strtotime
<?php
$now = time();
printf("%20s : %s\n", 'now', date('Y-m-d H:i:s', $now));
foreach( array("tomorrow", "+ 3 days","3 months 30 days","march 30, 2011") as $userinput ) {
$ts = strtotime($userinput, $now);
printf("%20s : %s\n", $userinput, date('Y-m-d H:i:s', $ts));
}打印
now : 2010-08-08 09:44:49
tomorrow : 2010-08-09 00:00:00
+ 3 days : 2010-08-11 09:44:49
3 months 30 days : 2010-12-08 09:44:49
march 30, 2011 : 2011-03-30 00:00:00发布于 2010-08-08 15:33:45
我见过的最好的实现之一就是这个javascript。它能做你想要的,但是在客户端!它不是php,但既然它是客户端,它的使用应该非常适合你的需要!
发布于 2010-08-08 15:45:48
函数strtotime()将解析许多“自然语言”时间表达式。http://www.php.net/manual/en/function.strtotime.php
此外,DateTime类使用相同的解析器,但它可以保存更大范围的日期http://www.php.net/manual/en/book.datetime.php
https://stackoverflow.com/questions/3433433
复制相似问题