Home > Web Front-end > JS Tutorial > js uses Date object to process time implementation ideas and code_Basic knowledge

js uses Date object to process time implementation ideas and code_Basic knowledge

WBOY
Release: 2016-05-16 17:42:27
Original
1019 people have browsed it
Let’s talk about this application scenario first:
Read data from an XML file, and then return the data inside to the page for drawing using a third-party plug-in.

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

var date = new Date();
//The input field with id time contains the time information extracted from 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 hours, minutes and seconds (such as 083100). After taking out the data, you can use setHours, setMinutes , setSeconds and other time-setting functions to instantiate the Date object.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template