Display Day of Week in Javascript

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

0 point/0 review File has been tested

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

Display Day of Week in Javascript Posted on 21-09-2016  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. 5/10 366

Comment:

To comment you must be logged in members.

Files with category

  • AngularJS and REST API

    AngularJS and REST API

    View: 31    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: 72    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: 45    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: 48    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...

  • Brief Introduction of SocketPro High Performance and Scalable Persistent Message Queue

    Brief Introduction of SocketPro High Performance and Scalable Persistent Message Queue

    View: 156    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Continuous in-line request/result batching, real-time stream sending/processing, asynchronous data transferring and parallel computation for best performance and scalability

  • Iteration Over Java Collections with High Performance

    Iteration Over Java Collections with High Performance

    View: 41    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Java developers usually deal with Collections such as ArrayList, HashSet, Java 8 come with lambda and streaming API helps us to easily work with Collections. In most cases, we work with few thousands of items and performance isn't a concern. But in...

  • SR2JLIB - A Symbolic Regression Library for Java

    SR2JLIB - A Symbolic Regression Library for Java

    View: 46    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Grammar-Guided Genetic Programming library featuring: multi-threading, just-in-time compilation of individuals, dynamic class loading, and JNI interfacing with C/C++ code

  • Yet Another Fluent JDBC Wrapper in 200 Lines of Code

    Yet Another Fluent JDBC Wrapper in 200 Lines of Code

    View: 54    Download: 0   Comment: 0

    Category: Javascript     Fields: Other

    Those who are not convinced to use Hibernate to manage persistence are forced to use plain old JDBC API. Though powerful, it requires lot of typing to get it right. For example, retrieving user data from database often requires such code snippet:

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