在JavaScript中将日期格式化为MM / dd / yyyy [英] Format date to MM/dd/yyyy in JavaScript

查看:105
本文介绍了在JavaScript中将日期格式化为MM / dd / yyyy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的日期格式'2010-10-11T00:00:00 + 05:30'。我必须使用JavaScript或jQuery格式化为 MM / dd / yyyy 。任何人都可以帮我这样做。

I have a dateformat like this '2010-10-11T00:00:00+05:30'. I have to format in to MM/dd/yyyy using JavaScript or jQuery . Anyone help me to do the same.

推荐答案

试试这个;请记住,JavaScript月份为0索引,而天数为1索引。

Try this; bear in mind that JavaScript months are 0-indexed, whilst days are 1-indexed.

var date = new Date('2010-10-11T00:00:00+05:30');
alert((date.getMonth() + 1) + '/' + date.getDate() + '/' +  date.getFullYear());

这篇关于在JavaScript中将日期格式化为MM / dd / yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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