在JavaScript中以日期/月/年格式获取当前日期

在JavaScript中获取当前日期 (Getting current date in JavaScript)

To get the current date in JavaScript, we need to use three library functions of Date class,

在JavaScript中获取当前日期 ,我们需要使用Date类的三个库函数,

  1. Date getDate() Method – It returns current date (day of the month)

    Date getDate()方法 –返回当前日期(每月的某天)

  2. Date getMonth() Method – It returns current month of the year

    Date getMonth()方法 –返回一年中的当前月份

  3. Date getFullYear() Method – It returns current year in 4 digits format

    Date getFullYear()方法 –以4位数字格式返回当前年份

Note: To call these functions, we need to create an object to the Date class using Date class constructor.

注意:要调用这些函数,我们需要使用Date类的构造函数为Date类创建一个对象。

Examples:

例子:

    Date class constructor:
    var dt = new Date();

    Function calls:
    dt.getDate();
    dt.getMonth()+1;
    dt.getFullYear();
    
    Output:
    4
    3
    2019

JavaScript code to get the current date in Date / Month / Year format

JavaScript代码以日期/月/年格式获取当前日期

<html>
<head><title>JavaScipt Example</title></head>

<body>
<script>
	var dt = new Date(); //Date constructor 
	var dd = dt.getDate();
	var mm = dt.getMonth()+1;
	var yy = dt.getFullYear();
	//printing date
	document.write("Current date is= " + dd + "/" + mm + "/" + yy + "<br>");
</script>
</body>
</html>

Output

输出量

Current date is= 4/3/2019


翻译自: https://www.includehelp.com/code-snippets/get-current-date-in-date-month-year-format-in-javascript.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值