以开始日期作为函数变量的计数计时器
我是 javascript 的新手,正在尝试创建一个计数计时器,它可以将某个日期作为输入并计算自该日期以来经过的时间。
我目前正在使用 http://keith-wood.name/countdown.html,但我遇到了 2 个问题
1)我不知道如何将输入日期添加为函数变量。我在这个论坛上发现了另一个类似的问题 - Jquery Countup Timer,但他们使用的是固定日期与可变输入日期相反。
2)如何确保变量输入的日期符合特定的格式?目前我正在尝试从 mysql 数据库中读取输入日期,该数据库将日期时间戳记为 2010-06-17 15:12:30,但我不认为这是jquery插件将读取的日期格式。有没有办法解析这个日期以使格式匹配?
非常感谢任何可以提供帮助的人!
史蒂夫
I'm new to javascript and was trying to create a countup timer that could take a certain date as an input and count the time that has passed since that date.
I'm currently using a jquery plugin from http://keith-wood.name/countdown.html, but I'm having 2 problems
1) I can't figure out how to add the input date as a function variable. I found another question on this forum that was similar - Jquery Countup Timer, but they were using a fixed date as opposed to a variable input date.
2) How do I ensure that the variable input date conforms to a specific format? Currently I'm trying to read the input date out of a mysql database which timestamps the dates as
2010-06-17 15:12:30, but I don't think that this is the date format that the jquery plugin will read. Is there a way to parse this date so that the formats match up?
Thanks very much to anyone that can help!
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个例子。
http://jsfiddle.net/HXf5v/
您所需要做的就是创建一个获取日期的 JavaScript 函数对象作为参数
,例如:
或者,您也可以始终创建一个 jquery 函数。
然后你可以像这样调用 jquery 函数:
至于格式化一个新的 Date() 对象。你应该看看:
http://www.w3schools.com/jS/js_obj_date.asp< /a>
表明您可以创建一个日期对象,如下所示:
Here is an example.
http://jsfiddle.net/HXf5v/
All you need to do is create a javascript function that takes the Date object as a parameter
something like:
Alternatively, you could also always create a jquery function.
and then you can invoke the jquery function like so:
As for formatting a new Date() object. you should take a look at:
http://www.w3schools.com/jS/js_obj_date.asp
which states that you can create a date object like this:
以下是从文本框中获取日期并将其用作开始日期的示例:
使用输入示例进行计数
javascript 可以通过接受几种不同格式的字符串来创建新的日期。以下是这些格式的快速链接:javascript 日期
Here is an example taking in the date from a textbox and using it as the startdate:
countup with input exmample
javascript can create a new date by taking in a string in a few different formats. Here's a quick link to those formats: javascript date
将 mysql 日期转换为 javascript 日期对象:
使用示例:
希望这有助于实现您的目标
To transform the mysql date to a javascript date object:
Example of usage:
Hope this helps to achieve your goal