jQuery将日期从格式更改为另一种格式 [英] jQuery change date from format to another one

查看:133
本文介绍了jQuery将日期从格式更改为另一种格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我输入的ID为CldrFrom

日期如下:04/17/2014 换句话说 mm/dd/yyyy

It has date like this: 04/17/2014 in other words mm/dd/yyyy

我想将其更改为这种格式17-04-2014 换句话说 dd-mm-yyyy

I want to change it to this format 17-04-2014 in other words dd-mm-yyyy

我想在jQuery中做到这一点.

I want to do that in jQuery.

var currentDate = $(#CldrFrom").val();
val = val.replace("/", "-");

所以我用-替换了/,但是我仍然需要将第一天而不是月份定为第一天. 怎么样?

So I replaced the / with - but I still need to make the day as the first not the month. how please?

获取日期,我正在使用日期选择器库. 我这样称呼它:

to take the date I am using a datepicker library. I call it like this:

$("#CldrFrom, #CldrTo").datepicker();

反正有,所以我直接让图书馆以这种格式打印日期dd-mm-yyyy?

is there anyway so directly I make that library prints dates in this format dd-mm-yyyy ?

推荐答案

只需按所需顺序拆分并加入

Just split and join it together in the order you want

var currentDate = $("#CldrFrom").val();
var dateArr     = currentDate.split('/');
var val         = dateArr[1] + '-' + dateArr[0]  + '-' + dateArr[2];

FIDDLE

这篇关于jQuery将日期从格式更改为另一种格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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