如何使用javascript/jquery反转日期格式yyyy-mm-dd? [英] How to reverse date format yyyy-mm-dd using javascript/jquery?

查看:47
本文介绍了如何使用javascript/jquery反转日期格式yyyy-mm-dd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将jquery中格式为2016-10-15的数据的日期更改为15-10-2016的日期.我尝试并管理显示为2016-10-15的输出.我在jquery ajax中捕获了此结果从数据库中获取的页面.

$.each(req,function(i,item){
    var val=$.format.date(req[i].from_date, "dd/MMM/yyyy");
    console.log(val);   //'2016-10-15'
});

解决方案

您可以使用本机javascript函数来完成这项工作.使用 .split() 分割日期通过-分隔符分成数组并使用 ,然后使用 .join()

 var date = "2016-10-15";
date = date.split("-").reverse().join("-");
console.log(date); 

I want to change the date for of data which is in format 2016-10-15 to d-m-yy format in jquery as 15-10-2016.I tried and console the output it shows 2016-10-15.I caught this result in jquery ajax page which is fetched from database.

$.each(req,function(i,item){
    var val=$.format.date(req[i].from_date, "dd/MMM/yyyy");
    console.log(val);   //'2016-10-15'
});

解决方案

You can do this work use native javascript functions. Use .split() to split date by - delimiter into array and invert array using .reverse() and convert array to sting using .join()

var date = "2016-10-15";
date = date.split("-").reverse().join("-");
console.log(date);

这篇关于如何使用javascript/jquery反转日期格式yyyy-mm-dd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆