Loading...

Display Day of Week in Javascript

View: 435    Dowload: 0   Comment: 0   Post by: hanhga   Category: Javascript   Fields: Other

How to display day of week in Javascript.

In my previous tutorial i  explained how to get current date and time in javascript. In previous tutorial i discussed about date object. Let’s quickly revise it.

How to Display Day of Week in Javascript

Let’s create a date object.

var date = new Date();
 
/* Print it on console */
 
console.log(date);
 
/* Output */
 
Fri Mar 25 2016 17:57:42 GMT+0530 (IST)

Date provides getDay() method which returns the day number of the week, starting with Sunday on 0 (zero) and so on.

Today is Friday so if i use this method it will return 5.

var date = new Date();
 
console.log(date.getDay());
 
/* Output */
How to Print Name of the WeekDay using  Javascript

Let’s create a simple method which prints the name of week day.

function printWeekDay () {
/* Create a date object */
var date = new Date();
/* Create an array of week name */
var week = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
console.log(week[date.getDay()]);  
/* Explanation
* date.getDay() return day number (suppose it's 5)
* week[5] return array value on that index
*/
}

Print Day of Week using Date in Javascript

Suppose if i enter following date 10/11/2009, print the day of week on the input date.

/* Print day of week */
 
function findDay(myDate) {
    
    var date = new Date(myDate);
    
    var week = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
    
    console.log(week[date.getDay()]);
} 
 
 
findDay(10/11/2009); // Print Sunday
 
findDay(11/10/2010); // Print Wednesday

Display Day of Week in Javascript

In my previous tutorial i explained how to get current date and time in javascript. In previous tutorial i discussed about date object. Let’s quickly revise it.

Posted on 21-09-2016 

Comment:

To comment you must be logged in members.

Files with category

  • Mini Youtube Using ReactJS

    Mini Youtube Using ReactJS

    View: 25    Download: 2   Comment: 0

    Category: Javascript     Fields: none

    This is one the best starter for ReactJS. MiniYoutube as the name suggests is a youtube like website developed using reactJS and youtube API. This project actually let's you search , play and list youtube videos. Do check it out and start learning...

  • Angular 6 Starter with Laravel 5.6 API Service

    Angular 6 Starter with Laravel 5.6 API Service

    View: 62    Download: 0   Comment: 0

    Category: Javascript     Fields: none

    Angular 6 and Laravel 5.6 This project is a starter for creating interface with Angular using bootstrap && css && sass and using Laravel 5.6 for api requests. Demo Installation This project is divided in two parts (projects) and before use them you...

  • Simple Richtext Editor Based on pellJS

    Simple Richtext Editor Based on pellJS

    View: 26    Download: 0   Comment: 0

    Category: Javascript     Fields: none

    A simple visual editor for websites using the pell javascipt. It also has the option to switch between visual editor mode and source code mode. I will upload an update for new functionality soon. Source Code Editor Visual Editor

  • Data Visualization for BI: How to Design Layouts for .NET Financial Reports

    Data Visualization for BI: How to Design Layouts for .NET Financial Reports

    View: 37    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    With the Active Reports Server, you can have a multi-tenant environment where users from various departments, companies, or other specifications can log in, view their reports (and only their reports), export the data, or set up a distribution...

  • AngularJS and REST API

    AngularJS and REST API

    View: 204    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    This is a tutorial for those interested in a quick introduction to AngularJS and REST API. We will build the familiar Periodic Table of the Elements found in every chemistry textbook, and allow the user to select a Chemical Element by clicking on...

  • Collective Intelligence, Recommending Items Based on Similar Users' Taste

    Collective Intelligence, Recommending Items Based on Similar Users' Taste

    View: 168    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Using Collaborative Filtering to find people who share tastes, and for making automatic recommendations based on things that other people like.

  • Think Like a Bird for Better Parallel Programming

    Think Like a Bird for Better Parallel Programming

    View: 157    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Coding an application to run in parallel is hard, right? I mean, it must be hard or we’d see parallel programs everywhere. All we'd see are slick parallel apps that use every available core effortlessly. Instead multi-threaded apps are the exception...

  • Getting Started with the Bing Search APIs

    Getting Started with the Bing Search APIs

    View: 169    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Bing Search API is a set of REST interfaces that find web pages, news, images, videos, entities, related searches, spelling corrections, and more in response to queries from any programming language that can generate a web request. Applications that...

 
File suggestion for you
Loading...
File top downloads
Loading...
Loading...
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd