简体   繁体   中英

Date and time widget in Dojo

Dojo has two widgets:

NOTE: I am using Dojo programmatically.

I want the user to enter a date and a time, and then send the server the "mixed" value of the lot (that is, that date + time).

I realise that I need to manipulate the two values before the submt() . Is there an established way to do this? Surely I am not the only person on the planet needing a simple Date/Time form?

Well, if you use:

registry.byId("myTimeTxtBox").get("value");

You get a Date object containing the time value and the date is the epoch itself. This means that if you select 1 AM, it will return the time at 01-01-1970 01:00:00 . You can then retrieve the unix timestamp (number of milliseconds since 01-01-1970 00:00:00 ) which will give you the amount of time in milliseconds by doing:

var timeEpoch = registry.byId("myTimeTxtBox").get("value").getTime();

If you do the same with your date textbox:

var dateEpoch = registry.byId("myDateTxtBox").get("value").getTime();

And add both to each other, you will get the UNIX timestamp of your date + time, converting it back to a Date object is easy as well:

new Date(dateEpoch + timeEpoch);

I also made a small JSFiddle to demonstrate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM