简体   繁体   English

整个网页上的HTML&CSS更改日期格式

[英]HTML&CSS Change Date Formatting On Whole Web Page

I am working on a portlet which will be used by multiple users throughout the world, therefore we would like to change the basic date format of EVERYTHING on an Html page from default to DD/MMM/YY where MMM is an abbreviation because the default is somewhat confusing depending of your country (aka USA or somewhere else) 我正在研究一个Portlet,该Portlet将被全世界的多个用户使用,因此,我们希望将HTML页面上EVERYTHING的基本日期格式从默认更改为DD / MMM / YY ,其中MMM是缩写,因为默认为根据您所在的国家(又名美国或其他地方)而有些混乱

aka 05/05/2014 should show up as 05/May/14
and 06/08/2015 should show up as 06/Aug/15

Since all of the dates need to be written that way, maybe it's only a line of code in the CSS or HTML file? 由于所有日期都需要以这种方式编写,因此也许只是CSS或HTML文件中的一行代码? I looked around and couldn't find anything about abbreviated dates, therefore I'd rather directly ask the professionals. 我环顾四周,找不到关于缩写日期的任何信息,因此,我宁愿直接询问专业人员。

I would wrap all dates in a <time> element , then use JavaScript to convert that to a local date format . 我将所有日期包装在<time>元素中 ,然后使用JavaScript将其转换为本地日期格式

HTML: HTML:

Published <time datetime="2011-07-03">07/03</time>

JS: JS:

var elements = document.getElementsByTagName("time");
for (var i=0; i<elements.length; i++) {
    var dat = new Date('UTC:'+elements[i].getAttribute('datetime'));
    elements[i].innerHTML = dat.toLocaleDateString();
}

http://jsfiddle.net/mblase75/7yF5v/ http://jsfiddle.net/mblase75/7yF5v/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM