本文介绍了转换日期(05/12/2011至12)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将日期隐藏到st,nd,rd或th之后的日期,这取决于一天,我是javascript的新手,所以不知道从哪里开始。 p>
例如
05/01/2011 = 1st
05/02/2011 = 2nd
05/03/2011 = 3rd
05/12/2011 = 12th
05/22/2011 = 22nd
谢谢
解决方案
首先,获取日期:
var date = myval.getDate();
然后找到后缀:
function get_nth_suffix(date){
switch(date){
case 1:
案例21:
案例31:
返回'st';
案例2:
案例22:
返回'nd';
案例3:
案例23:
返回'rd';
默认值:
返回'th';
}
}
演示在
I am trying to covert the date to the day number followed by "st", "nd", "rd" or "th depending on the day. I am new to javascript so have no idea where to start.
E.g.
05/01/2011 = 1st
05/02/2011 = 2nd
05/03/2011 = 3rd
05/12/2011 = 12th
05/22/2011 = 22nd
Thanks
解决方案
First, get the date:
var date = myval.getDate();
Then find the suffix:
function get_nth_suffix(date) {
switch (date) {
case 1:
case 21:
case 31:
return 'st';
case 2:
case 22:
return 'nd';
case 3:
case 23:
return 'rd';
default:
return 'th';
}
}
demo at http://jsfiddle.net/DZPSw/
这篇关于转换日期(05/12/2011至12)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!