如何在javascript中更改日期选择器值的日期格式
我在stackoverflow中已经问了很多与我的问题相关的问题,但我仍然找不到任何解决方案。我试图在javascript函数中从datpicker获取值,但无法更改其格式。默认情况下,它以mm/dd/yy格式显示,我希望以yyyy-mm-dd格式显示。谁能帮忙吗 下面是我的html代码:如何在javascript中更改日期选择器值的日期格式,javascript,html,datepicker,date-formatting,Javascript,Html,Datepicker,Date Formatting,我在stackoverflow中已经问了很多与我的问题相关的问题,但我仍然找不到任何解决方案。我试图在javascript函数中从datpicker获取值,但无法更改其格式。默认情况下,它以mm/dd/yy格式显示,我希望以yyyy-mm-dd格式显示。谁能帮忙吗 下面是我的html代码: <html xmlns:h="http://xmlns.jcp.org/jsf/html"> <h:head> <script> f
<html xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<script>
function getdate()
{
alert("Entered function");
var date = $('#fromdate').val();
$.datepicker.formatDate( 'yy-mm-dd' ,date );
alert(date); }
</script>
</h:head>
<body>
<input type="text" id="fromdate" class="form-control dpd1" name="from"placeholder="Select From Date"></input>
<span class="input-group-addon">To</span>
<input type="text" id="todate" class="form-control dpd2" name="to" placeholder="Select To Date" ></input>
<input type="button" onclick="getdate()" value="Change Date"></input>
</body>
</html>
函数getdate()
{
警报(“输入功能”);
var date=$('#fromdate').val();
$.datepicker.formatDate('yy-mm-dd',日期);
警报(日期);}
到
提前感谢。
<script>
$(document).ready(function(){
$('#datepicker').datepicker({ dateFormat: 'yy-mm-dd' });
});
function getdate()
{
alert("Entered function");
var date = $('#fromdate').val();
alert(date);
}
</script>
$(文档).ready(函数(){
$('#datepicker').datepicker({dateFormat:'yy-mm-dd'});
});
函数getdate()
{
警报(“输入功能”);
var date=$('#fromdate').val();
警报(日期);
}
$(文档).ready(函数(){
$('#datepicker').datepicker({dateFormat:'yy-mm-dd'});
});
函数getdate()
{
警报(“输入功能”);
var date=$('#fromdate').val();
警报(日期);
}
日期的格式可以是以下任意字符的组合:
d – day of month (single digit where applicable)
dd – day of month (two digits)
m – month of year (single digit where applicable)
mm – month of year (two digits)
y – year (two digits)
yy – year (four digits)
D – short day name
DD – full day name
M – short month name
MM – long month name
'...' – any literal text string
@ - UNIX timestamp (milliseconds since 01/01/1970)
日期的格式可以是以下任意字符的组合:
d – day of month (single digit where applicable)
dd – day of month (two digits)
m – month of year (single digit where applicable)
mm – month of year (two digits)
y – year (two digits)
yy – year (four digits)
D – short day name
DD – full day name
M – short month name
MM – long month name
'...' – any literal text string
@ - UNIX timestamp (milliseconds since 01/01/1970)
您需要将formatDate调用的结果分配给日期对象。然后你可以提醒它
您需要将formatDate调用的结果分配给日期对象。然后你可以提醒它。HTML
<input type="text" id="fromdate" class="datepicker form-control dpd1" name="from" placeholder="Select From Date"></input> <span class="input-group-addon">To</span>
<input type="text" id="todate" class="datepicker form-control dpd2" name="to" placeholder="Select To Date"></input>
<input type="button" class="getdate" value="Change Date"></input>
HTML
<input type="text" id="fromdate" class="datepicker form-control dpd1" name="from" placeholder="Select From Date"></input> <span class="input-group-addon">To</span>
<input type="text" id="todate" class="datepicker form-control dpd2" name="to" placeholder="Select To Date"></input>
<input type="button" class="getdate" value="Change Date"></input>
这对我很有用
<input type="text" id="fromdate" class="form-control dpd1" name="from"placeholder="Select From Date"></input>
$('#fromdate').datepicker({
format: 'yyyy/mm/dd'
});
$('#fromdate')。日期选择器({
格式:“yyyy/mm/dd”
});
它对我很有用
<input type="text" id="fromdate" class="form-control dpd1" name="from"placeholder="Select From Date"></input>
$('#fromdate').datepicker({
format: 'yyyy/mm/dd'
});
$('#fromdate')。日期选择器({
格式:“yyyy/mm/dd”
});
var date=$('#datepicker').datepicker({dateFormat:'yy-mm-dd'}).val()代码>尝试此操作它仍然显示相同的问题。实际上,它从datepicker获取的格式与通过脚本显示的格式相同。它没有改变或格式。你能发布这个问题的JSFIDLE吗?我正在尝试创建JSFIDLE,但是datepicker没有附加到文本框中,等待会很快发布链接。你是在寻找类似var date=$('#datepicker').datepicker({dateFormat:'yy-mm-dd').val()的内容吗代码>尝试此操作它仍然显示相同的问题。实际上,它从datepicker获取的格式与通过脚本显示的格式相同。它没有更改或格式。你能发布此问题的JSFIDLE吗?我正在尝试创建JSFIDLE,但datepicker没有附加到文本框中,等待将很快发布链接。你是否正在寻找类似于警报(日期)的内容,但它不起作用。我想我的密码有错误。必须再次查找。警报(日期)仅不起作用。我想我的密码有错误。我得再找一次。