HTML显示当前日期 [英] HTML Display Current date

查看:87
本文介绍了HTML显示当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用名为"clickfunnels"的网站构建器,但它们不支持允许我显示当前日期的功能.但是,我可以向其中添加自定义html.

I am using website builder called 'clickfunnels', and they don't support feature that would allow me to display current date. But, I can add custom html to it.

我想知道是否有人知道如何以dd/mm/yyyy格式显示网站当前日期

I was wondering if anyone knows how to show on website current date in format: dd/mm/yyyy

目前我已经尝试过:

<p id="date"></p>
<script>
document.getElementById("date").innerHTML = Date();
</script>

这可行,但是它显示的日期是这样的:

And this works, but it displays date likes this:

2015年9月12日星期六格林尼治标准时间+0200(时区....)

Sat Sep 12 2015 16:40:10 GMT+0200 (Timezone.... )

推荐答案

这是一种方法.您必须从日期对象(日,月和年)中获取各个组件,然后根据需要构建并设置字符串格式.

Here's one way. You have to get the individual components from the date object (day, month & year) and then build and format the string however you wish.

n =  new Date();
y = n.getFullYear();
m = n.getMonth() + 1;
d = n.getDate();
document.getElementById("date").innerHTML = m + "/" + d + "/" + y;

<p id="date"></p>

这篇关于HTML显示当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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