JavaScript Conversion Date-qualified

Source: Internet
Author: User

How JavaScript converts a time date to a Date object:
Sometimes you need to tell a string of time and date to convert to a date time object, the following is a simple example to provide a solution, of course, is a way of thinking, you can make some modifications to achieve extrapolate effect. For example, here is a time-date string:

2013-9-15 8:25:30

These are converted to time objects.
The code is as follows:

var timestr= "2013-9-15 8:25:30"; var strarray=timestr.split (""); var strdate=strarray[0].split ("-"); var strtime=strarray[1].split (":"); var timeobj=new Date (Strdate[0], (Strdate[1]-parseint (1)), strdate[2],strtime[0],strtime[1],strtime[2]) Console.log (Timeobj.getfullyear ())

The above code can output 2013, indicating that we have successfully converted the time-date string to the time object.

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=9184

JavaScript Conversion Date-qualified

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.