English 中文(简体)
格式
原标题:Format a date after putting it in a variable?

我用一个日期来请某个人上下周。

html基本如此:

<form method="post" action="">
    <input type="text" id="beginDate" />
    <input type="text" id="endDate" />
</form>

j现在就是:

<script type="text/javascript">
    $(function () {
        $("#beginDate").datepicker(
        { dateFormat: "dd-mm-yy",
            onSelect: function () {
                var mon = $(this).datepicker( getDate );
                mon.setDate(mon.getDate() + 1 - (mon.getDay() || 7));
                var sun = new Date(mon.getTime());
                sun.setDate(sun.getDate() + 6);
                $(this).val(mon);
                $( #endDate ).val(sun);
            }
        });
    });
</script>

著作,类型...... 在我的文本箱中设置了<条码>2011年第21号:00:00 GMT+0100和Sun Nov 27 2011 00:00:00 GMT+0100

I want them to be in a "dd-mm-yyyy" format, so just 21/11/2011. I tried things such as .formatDate, but that does not seem to work.

我知道,我可以做些什么,例如<条码>.GetDay()+“/”+ mon.GetMonth()+“/”等,但javascript必须具备某种适当的日期格式。

最佳回答

There is no date format function in JavaScript itself, but you are using jQuery ui so try this:

$( #endDate ).val($.datepicker.formatDate( dd/mm/yy , sun));
问题回答

javascript must have some kind of proper date formatter, right?

你们会 t你们,但没有。 贵组织的解决办法是最佳利用。 • 将日期加在一起,但不要忘记在<条形码>上添加1号。

var dateString = mon.GetDay() + "/" + (mon.GetMonth() + 1) + "/" + mon.getFullYear();

您可以使用一只冰箱,提供其他语文通常提供的日期编排功能,http://blog.stevenlevithan.com/archives/date-format”rel=“nofollow”here





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签