在datePicker中获取所选值并对其进行格式化 [英] get selected value in datePicker and format it
本文介绍了在datePicker中获取所选值并对其进行格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在datePicker中选择 20.04.2012
。我想得到这个值,将其格式化并存储在变量中。
我使用这个代码:
In the datePicker selected 20.04.2012
. I want to get this value, format it and store in a variable.
I uses this code:
var date = $("#scheduleDate").datepicker({ dateFormat: 'dd,MM,yyyy' }).val();
但结果是 20.04.2012
。
此外,我尝试了这个代码:
But result is 20.04.2012
.
Also, I tryed this code:
var dateTypeVar = $('#scheduleDate').datepicker('getDate');
$.datepicker.formatDate('dd-MM-yy', dateTypeVar);
结果是 Fri Apr 20 2012 00:00:00 GMT + 0600
。
我想得到以下内容: 20,2012年4月
如何正确格式化?
谢谢。
I want to get the following: 20, April, 2012
How to format properly?
Thanks.
推荐答案
输入值执行此操作:
If you want to take the formatted value of input do this :
$("input").datepicker({ dateFormat: 'dd, mm, yy' });
稍后在代码中设置日期可以通过
later in your code when the date is set you could get it by
dateVariable = $("input").val();
如果您只想使用datepicker格式化值,则可能需要使用实用程序
If you want just to take a formatted value with datepicker you might want to use the utility
dateString = $.datepicker.formatDate('dd, MM, yy', new Date("20 April 2012"));
I've updated the jsfiddle for experimenting with this
这篇关于在datePicker中获取所选值并对其进行格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文