2013-07-26 38 views
-3

請問如何獲得當前時間?我想用前面的文字顯示當前時間。如何獲得jquery mobile或jquery的當前時間

例子:

我不得不採取在其中我有一個標籤(有當前時間)一個div標籤,我想顯示一些文本前面。怎麼做?

其實我的問題是不同的。我正在解決突破部分的問題。

感謝

+0

可能重複(:

$('#divID').html("<b>" + hours + ":" + minutes + " " + "</b>"); 

然後,您可以在前面加上任何文本你前面那個想http://stackoverflow.com/questions/670290/jquery-gettime-function) – Sergio

+0

正文呢?爲了什麼? – svillamayor

+0

請解決這個問題 http://stackoverflow.com/questions/17881261/how-to-show-time-in-front-of-web-service-data-in-jquery-mobile/17881466?noredirect=1# 17881466 – Rohit

回答

8

你的意思是這樣的:

function date() { 
    var now = new Date(), 
     now = now.getHours()+':'+now.getMinutes()+':'+now.getSeconds(); 
    $('#time').html(now); 
} 

演示:http://jsfiddle.net/u32pU/

+0

正如我告訴過你,我有一個很大的問題,我打破了這個問題,部分原因你不明白..! – Rohit

+0

現在我想在這個時候顯示一些文本。爲什麼這不是水平的?這個小提琴http://jsfiddle.net/u32pU/1/ – Rohit

+0

試試這個:http://jsfiddle.net/u32pU/2/ –

10

你可能做的最好只是用常規的JavaScript的時間: Date對象有一個getTime方法: 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顯示它:

$('#divID').prepend('<p>Text before timestamp<p>'); 
[jQuery的的getTime函數]的
+0

現在我真正的問題是這樣的.. http://stackoverflow.com/questions/17881261/how-to-show-time-in-front-of-web-service-data-in-jquery-mobile/17881466?noredirect = 1#17881466 – Rohit

+0

實際上,我在幾秒鐘後從服務器獲取數據但是它沒有發送任何時間。因此,我需要在我的屏幕上顯示數據的時間。所以我需要在其中創建一個div我有兩個div一個div有當前時間,其他的是數據。我可以。你可以製作任何其他結構嗎? – Rohit

+0

文本不在同一行.. :(這裏是小提琴http://jsfiddle.net/DhneL/ – Rohit

相關問題