[英]Convert Mysql date with JavaScript to euro format
I am trying to convert a MySQL date to euro date with JavaScript. 我正在尝试使用JavaScript将MySQL日期转换为欧元日期。 but no success.
但没有成功。 My code is:
我的代码是:
var t = "2014-03-29 13:12:01".split(/[- :]/);
// Apply each element to the Date function
var d = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);
alert(d);
I get a result of something like this: Sat Mar 29 2014 23:24:28
我得到类似这样的结果:
Sat Mar 29 2014 23:24:28
Is there a way to set it to something like 31.12.2014
with JavaScript? 有没有办法使用JavaScript将其设置为
31.12.2014
? I can't use a server side language such as PHP. 我不能使用PHP等服务器端语言。
toLocaleString
comes to rescue if you don't care about options for Safari users. 如果您不关心Safari用户的选项,则
toLocaleString
可以拯救您。
var t = new Date("2014-03-29 13:12:01");
t.toLocaleString('fr');
// ⇒ "29/3/2014 13:12:01"
t.toLocaleString('ru');
// ⇒ "29.3.2014 13:12:01"
Hope it helps. 希望能帮助到你。
Try It :
var t = "2014-03-29 13:12:01".split(/[- :]/);
// Apply each element to the Date function
var d = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);
var curr_date = d.getDate(t);
var curr_month = d.getMonth(t) + 1; //Months are zero based
var curr_year = d.getFullYear(t);
var f = curr_date + "." + curr_month + "." + curr_year;
alert(f);
alert(d);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.