在javascript中以mm格式获取月份 [英] Get month in mm format in javascript

查看:94
本文介绍了在javascript中以mm格式获取月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 mm 格式检索当前日期的月份? (即05)

How do I retrieve the month from the current date in mm format? (i.e. "05")

这是我目前的代码:

var currentDate = new Date();
var currentMonth = currentDate.getMonth() + 1;


推荐答案

if (currentMonth < 10) { currentMonth = '0' + currentMonth; }

这篇关于在javascript中以mm格式获取月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆