jQuery获取当前时间
时间: 2023-11-02 10:21:56 浏览: 96
要使用jQuery获取当前时间,可以使用以下代码:
```javascript
var currentDate = new Date();
var currentYear = currentDate.getFullYear();
var currentMonth = currentDate.getMonth() + 1; // 月份从0开始,所以需要加1
var currentDay = currentDate.getDate();
var currentHour = currentDate.getHours();
var currentMinute = currentDate.getMinutes();
var currentSecond = currentDate.getSeconds();
var currentTime = currentYear + "-" + currentMonth + "-" + currentDay + " " + currentHour + ":" + currentMinute + ":" + currentSecond;
```
以上代码中,首先创建一个`Date`对象来获取当前时间。然后使用`getFullYear()`、`getMonth()`、`getDate()`、`getHours()`、`getMinutes()`和`getSeconds()`方法分别获取当前年份、月份、日期、小时、分钟和秒钟。最后,将这些值拼接成一个字符串来表示当前时间。
请注意,上述代码使用了原生JavaScript的`Date`对象,而非jQuery。因为获取当前时间是一个与浏览器相关的操作,并不需要依赖于jQuery。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [jquery获取当前时间](https://blog.csdn.net/jzz111/article/details/24732195)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Jquery获取当前时间](https://blog.csdn.net/hyc18272318789/article/details/125186893)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [Java企业报表管理系统源码](https://download.csdn.net/download/m0_55416028/88269629)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文