gpt4 book ai didi

javascript - LastModified 日期格式符合英国标准

转载 作者:行者123 更新时间:2023-12-02 16:10:10 28 4
gpt4 key购买 nike

我正在尝试显示网页上次加载的时间,并且需要将日期格式从 05/18/2015 11:47:39 更改为 18/05/2015 感谢我当前使用以下内容:

<script language="Javascript">

document.write("last refreshed: " + document.lastModified +"");
</SCRIPT>

最佳答案

您可以编写一个函数,将日期格式化为您所需的格式:

function formatAsUKDate(date) {
var day = padWithZero(date.getDate(), 2);
var month = padWithZero(date.getMonth()+1, 2);
var year = date.getFullYear();
return day + '/' + month + '/' + year;
}

function padWithZero(str, minLength) {
str = String(str);
while (str.length < minLength) {
str = '0' + str;
}
return str;
}

在你的 HTML 中:

<script language="Javascript">

document.write("last refreshed: " + formatAsUKDate(document.lastModified) +"");
</SCRIPT>

关于javascript - LastModified 日期格式符合英国标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30301294/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com