Dijit.form.DateTextBox value

I have the following text box with dojo dojo Date text type.

dojoType = "dijit.form.DateTextBox" required = "true" / ">

I use the following code to set dijit.form.DateTextBox

dijit.byId ('dtinv'). Attr ('value', new Date (TList [i] .getAttribute ("dtinv")));

tList [i] .getAttribute ("dtinv") has the value 2010-04-02

When the value is set, I see 4/1/2010. Always the date in the dojo date field shows one day less. Is there something I should take care of?

+4
source share
1 answer

Dojo and Dijit process Dates at local time, not GMT, which in itself could be a poor design choice, but on the condition that if you use dojo.date.stamp.fromISOString() or pass the string "2010-04-02" as the value in your HTML, you get April 2 at midnight in your local time. Pass it on to Digit and he will be happy. Using the new ES5 date constructor in Javascript will have different results:

(I'm in the eastern time zone)

 >>> new Date("2010-04-02") Thu Apr 01 2010 20:00:00 GMT-0400 (EST) {} 

which defines the date in GMT. However, the following object will work as expected with Dijit:

 >>> new Date(2010, 3, 2) Fri Apr 02 2010 00:00:00 GMT-0400 (EST) {} 

Also, the Javascript new Date constructor is poorly defined when it comes to accepting strings. I am not sure that the result you get is consistent across all browsers. It is recommended that you use dojo.date.stamp.fromISOString("2010-04-02") to obtain the appropriate Date object or ES5 ISO date methods, if available in new browsers.

+5
source

Source: https://habr.com/ru/post/1305747/


All Articles