jQuery时间和日期


                    

例如,我正在寻找使用jQuery的时间输出,希望知道访问者的浏览器和当前时间是几点(星期五,星期六,星期一等)。</ p>

有什么方法只能使用jQuery吗? 我不太喜欢javascript处理时间问题的方式。 </ p>

如果您推荐任何插件,请告诉我。</ p>

非常感谢!
苏扎。</ p>

编辑:</ p>

我希望避免子字符串javascript输出或转换结果。</ p>

不好用</ p>

  $(“#setime”)。yourtime(“ day”);
</ code> </ pre>

给我一​​天吗?
或</ p>

  $(“#setime”)。yourtime(“ hour”,24format);
</ code> </ pre>

以您需要的任何格式给您时间吗?</ p>

?</ p>
     </ div>

展开原文

原文

I am looking for a time output using jQuery, for example, would be great to know what time it is on the visitor's browser and the current day (friday,saturday,monday, etc...).

Is there any way to do it only with jQuery? I don't really like the way javascript handles time issues.

If you recommend any plugin, please tell me wich.

Thanks so much! Souza.

EDIT:

I'm looking to avoid substring javascript outputs, or convert the results.

Wouldn't be great to use

$("#setime").yourtime("day"); 

and give me the day? or

 $("#setime").yourtime("hour", 24format);

and give you the hour in any format you need?

?

2个回答


尝试:</ p>

  var currentTime = new Date();
</ code> </ pre>

它不是jQuery,但可以满足您的要求。</ p>

您还具有:</ p>

  var month = currentTime.getMonth()
var day = currentTime.getDate()
var年= currentTime.getFullYear()
var hours = currentTime.getHours()
var分钟= currentTime.getMinutes()
</ code> </ pre>

一起玩。</ p>
     </ div>

展开原文

原文

Try:

var currentTime = new Date();

It's not jQuery but it will do what you want.

You also have:

var month = currentTime.getMonth()
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()

To play with.


也许这就是您想要的?</ p>

http://crossbreeze.github.com/jquery-sensible-datetime/ </ p>

在此处下载: https://github.com/crossbreeze/jquery-sensible-datetime</ a> </ p>

如果没有,这是纯JS供您重用</ p>

  <br>
 var weekday = [“星期日”,“星期一”,“星期二”,“星期三”,“星期四”,“星期五”,“星期六”];<br>
 var monthname = [“ Jan”,“ Feb”,“ Mar”,“ Apr”,“ May”,“ Jun”,“ Jul”,“ Aug”,“ Sep”,“ Oct”,“ Nov”,“ Dec  “];<br>
 函数formatDate(d){<br>
   var text =“”;<br>
   文字+ =工作日[d.getDay()] +“”;<br>
   文字+ = d.getDate()+“”;<br>
   文字+ = monthname [d.getMonth()] +“”;<br>
   文字+ = d.getFullYear();<br>
   var hh = d.getHours();<br>
   var mm = d.getMinutes();<br>
   如果(hh <10)hh =“ 0” + hh;<br>
   如果(mm <10)mm =“ 0” + mm;<br>
   返回文字+“” + hh +“:” + mm;<br>
 }<br>
 $(document).ready(function(){<br>
   var d = new Date();<br>
   $(“#dateDiv”)。text(formatDate(d));<br>
 });<br>
 </ script><br>
 &lt;/ code&gt; &lt;/ pre&gt;<br>
     &lt;/ div&gt;</p>

展开原文

原文

Perhaps this is what you were looking for?

http://crossbreeze.github.com/jquery-sensible-datetime/

Download here: https://github.com/crossbreeze/jquery-sensible-datetime

If not, here is plain JS for you to reuse

<script type="text/javascript">
var weekday=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"," Saturday"];
var monthname=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
function formatDate(d) {
  var text = "";
  text += weekday[d.getDay()] + " ";
  text += d.getDate() + " ";
  text += monthname[d.getMonth()] + " ";
  text += d.getFullYear();
  var hh = d.getHours();
  var mm = d.getMinutes();
  if (hh<10) hh = "0"+hh;
  if (mm<10) mm = "0"+mm;
  return text +" "+hh+":"+mm; 
}
$(document).ready(function () {
  var d = new Date();
  $("#dateDiv").text(formatDate(d));
});
</script>

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐