Returns the day of the week and the day of the week of the javascript string.

Source: Internet
Author: User

Returns the day of the week and the day of the week of the javascript string.

The format of the date string returned by the server is as follows:

12:23:46 pm-01-19 pm-01-19 pm-01-19 pm-01-16 pm
It is required that the date of the week be converted into the following format:


First, convert the string to the date format.

Var str = '1970-01-20 12:03:12 '; dateStr = dateStr. replace (/-/g,'/'); var date = new Date (dateStr );
OK. Call the getDay () method after converting to the date format to determine the day of the week.

Var day = date. getDay ();

The complete method is as follows:

Function getDayOfWeek (dateStr) {var dayOfWeek = ""; dateStr = dateStr. replace (/-/g, '/'); var date = new Date (dateStr); switch (date. getDay () {case 0: dayOfWeek = 'sunday'; break; case 1: dayOfWeek = 'monday'; break; case 2: dayOfWeek = 'tues'; break; case 3: dayOfWeek = 'wedne'; break; case 4: dayOfWeek = 'thurs'; break; case 5: dayOfWeek = 'Friday'; break; case 6: dayOfWeek = 'satur'; break;} return dayOfWeek ;}
O (distinct _ distinct) O ~

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.