jQuery getTime函数 [英] jQuery getTime function
本文介绍了jQuery getTime函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以创建一个jQuery函数,使其获取当前日期和时间?我一直在寻找文档,但到目前为止还没有找到任何东西...
is it possible to create a jQuery function so that it gets current date and time? I've been looking around documentation but haven't found anything so far...
推荐答案
@nickf是正确的.但是,更精确一点:
@nickf's correct. However, to be a little more precise:
// if you try to print it, it will return something like:
// Sat Mar 21 2009 20:13:07 GMT-0400 (Eastern Daylight Time)
// This time comes from the user's machine.
var myDate = new Date();
因此,如果要将其显示为mm/dd/yyyy,请执行以下操作:
So if you want to display it as mm/dd/yyyy, you would do this:
var displayDate = (myDate.getMonth()+1) + '/' + (myDate.getDate()) + '/' + myDate.getFullYear();
查看Date对象的完整引用.不幸的是,打印出各种格式并不像使用其他服务器端语言那样好.因此,那里-很多-功能可在野外使用.
Check out the full reference of the Date object. Unfortunately it is not nearly as nice to print out various formats as it is with other server-side languages. For this reason there-are-many-functions available in the wild.
这篇关于jQuery getTime函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文