更改日期格式(Javascript)
我有这个代码:
var fd=1+self.theDate.getMonth() +'/'+ today+'/'+self.theDate.getFullYear();
它有效,但它的格式是月、日、年。
我需要将其更改为:日、月、年。
所以,我尝试了以下方法:
var fd=1+today +'/'+ self.theDate.getMonth()+'/'+self.theDate.getFullYear();
现在,我的更改不起作用。是我没做对还是我的改变对了?
谢谢
I have this code:
var fd=1+self.theDate.getMonth() +'/'+ today+'/'+self.theDate.getFullYear();
It works, but it's format is Month, Day, Year.
I need to change it to: Day, Month Year.
So, I tried this:
var fd=1+today +'/'+ self.theDate.getMonth()+'/'+self.theDate.getFullYear();
Now, my change does not work. Is it that I have not done it properly or is my change right?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我预计正确的答案是这样的:
这将单独保留今天,并将月份分组,以便它进行正确的数字加法而不是字符串连接。
I expect the correct answer is this:
This leaves today alone, and groups Month so that it does a proper number addition instead of string concatenation.
或者您可能更喜欢 22/05/2011
or perhaps you prefer 22/05/2011
您不再将
1
添加到月份,而是将其添加到今天
。确保将其括起来,因为"x" + 1 + 2 => “x12”
但“x” + (1 + 2) => “x3”
You are no longer adding
1
to the month, you are adding it totoday
. Make sure to parenthesize this since"x" + 1 + 2 => "x12"
but"x" + (1 + 2) => "x3"