Home  >  Article  >  Web Front-end  >  How to get today’s day of the week code in js

How to get today’s day of the week code in js

小云云
小云云Original
2018-02-24 13:13:372608browse

This article mainly shares with you how to get today's day of the week code in js. I hope it can help you.

  1.初级方法 
    var week = new Date().getDay(),str='今天是星期';
    if(week === 0){str += '日'}...
    或者switch..
  2.中级方法
  var week = new Date().getDay(), 
      arr = ['日', '一', '二', '三', '四', '五', '六'],
      str = '今天是星期'+arr[week];
  3.高级方法
  var str= '今天是星期'+'日一二三四五六'.charAt(new Date().getDay());

Related recommendations:

JS method of obtaining time

JS method of obtaining time function and extension function

js gets the time and converts between strings and timestamps_javascript skills

The above is the detailed content of How to get today’s day of the week code in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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