如何在jquery mobile或jquery中获取当前时间 [英] How to get current time in jquery mobile or jquery
问题描述
你能告诉我如何获得当前时间吗?我希望在其前面显示包含文字的当前时间。
Can you please tell me how to get current time? I want to display current time with text in front of it.
示例:
我必须带一个div标签,其中我有一个标签(有当前时间)前面我想要显示一些文字。怎么做?
I have to take one div tag in which i have one label (having current time) front of that i want to show some text. How to do that?
其实我的问题不同了。我正在解决破坏部分的问题。
Actually my problem is different. I am solving the problem in breaking parts.
谢谢
推荐答案
你可能最好只使用常规JavaScript:
date对象有一个getTime方法:
http://www.w3schools.com/jsref/jsref_gettime.asp
You'd probably do best just using regular JavaScript for the time: The date object has a getTime method: http://www.w3schools.com/jsref/jsref_gettime.asp
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10)
minutes = "0" + minutes
然后,使用jQuery你可以在你的div:
Then, using jQuery you could display it in your div:
$('#divID').html("<b>" + hours + ":" + minutes + " " + "</b>");
然后你可以在前面添加你想要的任何文字:
You can then prepend any text you want in front of that:
$('#divID').prepend('<p>Text before timestamp<p>');
这篇关于如何在jquery mobile或jquery中获取当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!