专题文章
时长:00:00更新时间:2024-03-18 06:05:59
在JavaScript中可以使用`Date`对象来获取当前时间。以下是如何获取当前时间的代码示例。```javascript。var currentDate = new Date()。console.log(currentDate)。```;运行以上代码会在控制台上打印当前时间的详细信息,包括年份、月份、日期、小时、分钟、秒等。如需获取特定格式的时间,可以使用`Date`对象的方法来获取指定部分的时间,例如。```javascript。var currentDate = new Date()。var year = currentDate.getFullYear()。var month = currentDate.getMonth() + 1;// 月份从0开始,需要加1。
查看详情