Js uses the Date object to process time Implementation ideas and code _ basic knowledge

Source: Internet
Author: User
This article mainly aims to read data from the XML file, and then return the data to the page using a third-party plug-in for plotting, and provides a detailed solution, if you are interested, you may find it helpful. Let's talk about this application scenario first.:
Read data from the XML file, and then return the data to the page using a third-party plug-in for plotting.

The data read in XML is of course a string type, and if you want to use the time mode of the X axis of the drawing plug-in (in this way, you can customize the data such as the X axis range and the format of the X axis data more reasonably ). The data must be converted to a standard time object. At this time, the built-in Date type in js comes in handy:

The Code is as follows:


Var date = new Date ();
// The input field with the id of time contains the time information extracted in xml.
Date. setHours ($ ("# time"). val (). substring (0, 2) + 8 );
Date. setMinutes ($ ("# time"). val (). substring (2, 4 ));
Date. setSeconds ($ ("# time"). val (). substring (4, 6 ));


The time type in XML is in the format of hour, minute, and second (for example, 083100 ), after obtaining the data, you can instantiate the Date object using time-setting functions such as setHours, setMinutes, and setSeconds.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.