使用javascript显示日期格式 [英] Display date format using javascript

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

问题描述

大家好。



我从美国格式的数据库中获取日期字段( MMddyyyy )但是我需要显示的是std日期格式,即 MM / dd / yyyy 使用 javascript / jquery



示例:如果来自数据库的值是 7242014 ,然后它将显示 7/24/2014



我尝试过使用子字符串但是如果几个月或几天是10或更多,那么它是不正确的。



请帮忙。

解决方案

< b>我尝试使用子字符串,但如果数月或数天是10或更多,则表示不正确。



试试这个.... ........



如果(parseint(MM)< 10){

MM ='0'+ MM

}



 if(parseint(DD)< ;   10 ){
DD = ' 0' + DD;
}


试试这个



 < span class =code-keyword><   script     type   =  text / javascript >  
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth()+ 1; //月数为零
var curr_year = d.getFullYear();
document.write(curr_date +/+ curr_month +/+ curr_year);
< / script >


Hi All.

I am getting date field from database in US-Format(MMddyyyy) but I need it to display is std date format i.e MM/dd/yyyy using javascript/jquery.

Example: If value from database is 7242014, then it will display 7/24/2014.

I have tried using substring but if months or days are 10 or more, then its not correct.

Please help.

解决方案

"I have tried using substring but if months or days are 10 or more, then its not correct."

Try this............

If (parseint(MM) <10 ) {
MM = '0'+MM
}

If (parseint(DD) < 10) {
DD = '0'+DD;
}


try this

<script type="text/javascript">
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1; //Months are zero based
    var curr_year = d.getFullYear();
    document.write(curr_date + "/" + curr_month + "/" + curr_year);
</script>


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

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