如何使用jQuery / Javascript更改日期格式? [英] How to change date format using jQuery/Javascript?
问题描述
$ date ='2013-04-01T19 :45:11.000Z'
$ cool = date('Ym-d',strtotime($ date));
如何在jQuery / Javascript中执行(PHP)?
谢谢!
您需要一个这样的格式的日期为javascript Sun ,01 Sep 13 08:06:57 +0000
所以在PHP中你需要做这样的事情
date_default_timezone_set('Australia / Perth');
echo date('D,d M y H:i:s')。+0000;
您可以尝试使用jQuery查看
$。get('dateformat.php',function(data){
date = new Date(data);
console.log(date)
});
然后,您可以根据需要格式化日期
您自己格式化日期对象的示例:
$。date = function(dateObj ){
var d = new Date(dateObj);
var day = d.getDate();
var month = d.getMonth()+ 1;
var year = d.getFullYear();
if(month< 10){
month =0+ month;
}
返回年+。 +月+。 +天
};
一个jquery插件可以帮助您格式化类似于php的日期 p>
https://github.com/phstc/jquery- dateFormat
您可以使用它来应用这样的格式
$。format.date(2009-12-18 10:54:50.546,测试:dd / MM / yyyy)
我想是这样。
Today I want to transfrom date into different format using jQuery/Javascript :
$date = '2013-04-01T19:45:11.000Z'
$cool = date('Y-m-d',strtotime($date));
How can I do that (PHP) in jQuery/Javascript ?
Thanks!
You need a date in such format for javascript Sun, 01 Sep 13 08:06:57 +0000
So in PHP you need to do something like this
date_default_timezone_set('Australia/Perth');
echo date('D, d M y H:i:s')." +0000";
And you can experiment with jQuery to check it
$.get('dateformat.php', function(data) {
date = new Date(data);
console.log(date);
});
Then you could format a date as you wish
Example for formatting date object on your own:
$.date = function(dateObj) {
var d = new Date(dateObj);
var day = d.getDate();
var month = d.getMonth() + 1;
var year = d.getFullYear();
if (month < 10) {
month = "0" + month;
}
return year + "." + month + "." + day;
};
A jquery plugin to help you format a date similar to php
https://github.com/phstc/jquery-dateFormat
You can use it to apply a format like this
$.format.date("2009-12-18 10:54:50.546", "Test: dd/MM/yyyy")
I think that's it.
这篇关于如何使用jQuery / Javascript更改日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!