如何通过 Javascript 将日期格式从 dd/mm/yyyy 更改为默认格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7075174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change date format from dd/mm/yyyy to default format through Javascript
提问by vinothini
In my Database i am having date in "dd/mm/yyyy" format. In the sucess function I am getting like '29/06/2006". I want to convert this form "dd/mm/yyyy" format to default format (default format means "Thu Jun 29 2006 00:00:00 GMT+0530 (India Standard Time)")
在我的数据库中,我有“dd/mm/yyyy”格式的日期。在成功函数中,我得到了“29/06/2006”。我想将此表单“dd/mm/yyyy”格式转换为默认格式(默认格式表示“Thu Jun 29 2006 00:00:00 GMT+0530 (印度标准时间)")
I tried the following ways
我尝试了以下方法
1) way
1)方式
xx = 29/06/2006
new Date(xx)
2)way
2种方法
dateFormat(xx, "ddd, mmmm dS, yyyy, h:MM:ss TT")
Both giving wrong date,month,year. Result as (Tue, May 6th, 2008, 12:00:00 AM)
两者都给出了错误的日期,月份,年份。结果为(2008 年 5 月 6 日,星期二,上午 12:00:00)
I am giving input as Jun 29 2006 but after conversion it'a showing May 6th, 2008.
我在 2006 年 6 月 29 日提供输入,但转换后显示为 2008 年 5 月 6 日。
采纳答案by Shebin
回答by Surendra
Try this:
试试这个:
var mydate = new Date(getDateFromFormat(/*Date value in string*/, /*Format of date sting*/));
回答by KooiInc
this could do it:
这可以做到:
var dt = '01/05/2011'.split(/\-|\s/) // allows for 01-05-2011 also
dat = new Date(dt.reverse().join('/'));