开发者

How to get date from dijit.form.DateTextBox in given format?

开发者 https://www.devze.com 2023-02-25 12:28 出处:网络
I have a dojo text boxin a html开发者_StackOverflow中文版 file.Now i want toretrieve the date from text box in a string format \'yyyy-mm-dd\'. How can i do it?

I have a dojo text box in a html开发者_StackOverflow中文版 file.Now i want to retrieve the date from text box in a string format 'yyyy-mm-dd'. How can i do it?

  dojoType="dijit.form.DateTextBox"

How can I do it?


Assuming you have a reference widget to your DateTextBox widget using something like dijit.byId(...) or dijit.byNode(dojo.query(...)), this will get the Javascript Date object and format it according to ISO 8601 standard (yyyy-mm-dd), independent of the display or the locale you happen to be using

 dojo.require('dojo.date.stamp');
 ...
 var dateObject = widget.get('value');
 var isoFormat = dojo.date.stamp.toISOString(dateObject, {selector: 'date'});


try this: HTML:

<input type="text" name="date1" id="date1" value="2005-12-30"
   dojotype="dijit.form.DateTextBox" required="true" />

To get displayed value you can use this method of date text box:

// get widget:
    var dtb = dijit.byId('date1');
// get value
    alert(dtb.get('displayedValue'));

NOTE*:

Dojo format the date according user locale.

IF you can use format which differs with user locale format you need specify constraint property for date text box.

<input type="text" name="date1" id="date1" value="2005-12-30" 
  constraints="{datePattern:'yyyy-MM-dd', strict:true}" 
  dojotype="dijit.form.DateTextBox" required="true" />

HTML Page - example


This is an old question, but you can just use the widget's toString method.

var isoString = dijit.byId(widgetId).toString();
0

精彩评论

暂无评论...
验证码 换一张
取 消