从jquery更改日期格式 [英] change date format from jquery
本文介绍了从jquery更改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个日期,我从jquery获得
I have this date, that I get from jquery
Wed Oct 30 2013 09:05:17 GMT-0800 (Hora estándar Pacífico (México))
我得到这个功能
var date = new Date();
var newdate = new Date(date);
newdate.setDate(newdate.getDate() + 7);
var nd = new Date(newdate);
$('#vigencia_receta_11').val(nd);
但是我只需要日期不是时间,我想格式化这样的日期DD / MM / YYYY
But I only need the date not the time, I want to format the date like this "DD/MM/YYYY"
推荐答案
我做了以下代码:
function myDateFormatter ("pass your date here") {
var d = new Date(dateObject);
var day = d.getDate();
var month = d.getMonth() + 1;
var year = d.getFullYear();
if (day < 10) {
day = "0" + day;
}
if (month < 10) {
month = "0" + month;
}
var date = day + "/" + month + "/" + year;
return date;
};
这篇关于从jquery更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文