admin管理员组文章数量:1289483
How to convert a "DD-MMM-YYYY" string to a date in Jquery?
I've a date in string "14-Jun-2014". I want to convert it to a date; something like this 14-06-2014
. For $("#InvoiceToDate").text();
I get this "14-Jun-2014"
So for
new Date($("#InvoiceToDate").text())
But its showing
Sat Jun 14 2014 00:00:00 GMT+0600 (Bangladesh Standard Time)
I've also tried this
new Date($("#InvoiceToDate").text()).toLocaleString('en-GB');
Now its showing almost what I wanted.
"06/08/2014 00:00:00"
How can I get only dd/MM/yyyy. Please help.
How to convert a "DD-MMM-YYYY" string to a date in Jquery?
I've a date in string "14-Jun-2014". I want to convert it to a date; something like this 14-06-2014
. For $("#InvoiceToDate").text();
I get this "14-Jun-2014"
So for
new Date($("#InvoiceToDate").text())
But its showing
Sat Jun 14 2014 00:00:00 GMT+0600 (Bangladesh Standard Time)
I've also tried this
new Date($("#InvoiceToDate").text()).toLocaleString('en-GB');
Now its showing almost what I wanted.
"06/08/2014 00:00:00"
How can I get only dd/MM/yyyy. Please help.
Share Improve this question edited Nov 7, 2014 at 7:14 Mahib asked Jun 13, 2014 at 13:19 MahibMahib 4,0636 gold badges57 silver badges63 bronze badges 2- I've tried this >> new Date($("#InvoiceToDate").text()) But its showing >> Sat Jun 14 2014 00:00:00 GMT+0600 (Bangladesh Standard Time) – Mahib Commented Jun 13, 2014 at 13:28
- 1 try like this: stackoverflow./questions/23532270/… – Uday Commented Jun 13, 2014 at 13:32
2 Answers
Reset to default 4I had similar kind of problem. This works for me.
var now = new Date("14-Jun-2014");
now.toLocaleDateString("en-GB");
This returns "14/06/2014" in Chrome.
UPDATE:
FF and IE wouldn't swallow "14-Jun-2014". However, if you could remove the dashes from the string and replace with spaces like "14 Jun 2014" then it will work on both browsers.
var now = new Date("14 Jun 2014");
now.toLocaleDateString("en-GB");
See if this helps.
Something like this:
var fecha = "14-Jun-2014";
var myDate = new Date(fecha);
console.log(myDate);
Fiddle: http://jsfiddle/robertrozas/pS8tc/1/
本文标签: javascriptHow to convert quotDDMMMYYYYquot string to dateStack Overflow
版权声明:本文标题:javascript - How to convert "DD-MMM-YYYY" string to date - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741468360a2380447.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论