在jquery中转换日期格式 [英] Convert date format in jquery
本文介绍了在jquery中转换日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要以2014-11-04格式显示的日期为yy mm dd
I need the date to show in this format 2014-11-04 as "yy mm dd"
目前,我的脚本仍然显示
Tue 2014年11月04日00:00:00 GMT + 0200(埃及标准时间)
Currently, my script still shows me Tue Nov 04 2014 00:00:00 GMT+0200 (Egypt Standard Time)
$(document).ready(function() {
var userDate = '04.11.2014';
from = userDate.split(".");
f = new Date(from[2], from[1] - 1, from[0]);
console.log(f);
});
推荐答案
可以使用date对象的方法p>
You can construct this using the date object's methods
var date = new Date(userDate),
yr = date.getFullYear(),
month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth(),
day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
newDate = yr + '-' + month + '-' + day;
console.log(newDate);
这篇关于在jquery中转换日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文