
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6710 Articles for Javascript

270 Views
To remove first array element, use the JavaScript shift() method. JavaScript array shift() method removes the first element from an array and returns that element.ExampleYou can try to run the following code to remove first array element and return it −Live Demo JavaScript Array shift Method var element = [30, 45, 70, 90, 110].shift(); document.write("Removed first element is : " + element ); OutputRemoved first element is : 30

5K+ Views
In this tutorial, we will learn to subtract minutes from the date in JavaScript. While developing the applications, programmers need to play with the dates many times. All JavaScript programmers are lucky enough that JavaScript contains the built-in date class with hundreds of different methods.In this tutorial, we will learn to subtract the minutes from the date in vanilla JavaScript using the date object and the Moment JS library.Using the getMinutes() and setMinutes() MethodsIn this approach, we will create a new date object and extract the minutes from that using the getMinutes() method.After that, we will update the minutes by ... Read More

9K+ Views
We will learn to convert the date object to a string with the format hh:mm:ss in JavaScript. It is a rear case that developers don’t use the date and time while developing the application. So, it is also important to learn to manipulate the dates. The default date object returns the date string. Maybe it can be weird as you don’t need to show everything from it. So, users can format the date string according to their requirements. Here, we will see different approaches to format the date string. Format the date using toISOString() method In this approach, we will ... Read More

359 Views
To compare two date objects with JavaScript, create two dates object and get the recent date to compare it with the custom date.ExampleYou can try to run the following code to compare two dates −Live Demo var date1, date2; date1 = new Date(); document.write(date1); date2 = new Date( "Dec 10, 2015 20:15:10" ); document.write(""+date2); if (date1 > date2) { document.write("Date1 is the recent date."); } else { document.write("Date 2 is the recent date."); } OutputMon May 28 2018 09:48:49 GMT+0530 (India Standard Time) Thu Dec 10 2015 20:15:10 GMT+0530 (India Standard Time) Date1 is the recent date

3K+ Views
To get the current year, use the getFullYear() JavaScript method. JavaScript date getFullYear() method returns the year of the specified date according to local time. The value returned by getFullYear() is an absolute number. For dates between the years 1000 and 9999, getFullYear() returns a four-digit number, for example, 2008.ExampleYou can try to run the following code to get the current year −Live Demo JavaScript getFullYear Method var dt = new Date("December 30, 2017 21:25:10"); document.write("getFullYear() : " + dt.getFullYear() ); OutputgetFullYear() : 2017

31K+ Views
In this tutorial, we will learn to check whether a JavaScript date is valid or not. Let’s understand why we need to validate the date in JavaScript by example. Suppose you have developed an application that takes some information in the submission form from the user. Users can make a mistake. What if they enter the wrong date in the input box? In such a case, developers need to validate the date. Here, we have three different methods to validate the date. Using the getTime() Method Using the isFinite() Method Using the Moment JS isValid() Method Using the ... Read More

486 Views
To initialize a JavaScript Date to midnight, set hours like the following −setHours(0,0,0,0);ExampleYou can try to run the following code to set a date to midnight −Live Demo var dt; dt = new Date(); dt.setHours(0,0,0,0); document.write(dt); OutputMon May 28 2018 00:00:00 GMT+0530 (India Standard Time)

7K+ Views
While developing the applications, sometimes it needs to compare the only date. For example, you are developing some apps in which users must adhere to the deadline and pay for the subscription. If the user pays at any time on or before the end date of the subscription, the user will be able to use the subscription continues. Otherwise, you need to stop the subscription. In this tutorial, we will learn to compare only the date part without comparing the time in JavaScript. In the above cases, we need to compare the two dates without focusing on the time. Approach ... Read More

234 Views
To convert a Unix timestamp to time, you can try to run the following code in JavaScript −ExampleLive Demo JavaScript Dates var unix_time = 1514791901 ; var date = new Date(unix_time*1000); // get hours var hrs = date.getHours(); // get minutes var min = "0" + date.getMinutes(); // get seconds var sec = "0" + date.getSeconds(); document.write("Time- "+hrs + ":" + min.substr(-2) + ":" + sec.substr(-2)); OutputTime- 13:01:41

4K+ Views
To format a JavaScript date into “yyyy-mm-dd” format, use the toISOString() method. It converts using ISO standard i.e.YYYY-MM-DDTHH:mm:ss.sssExampleYou can try to run the following code to format a date. Live Demo JavaScript Dates var date, res; date = new Date(); res = date.toISOString(); document.write(res); Output2018-12-15T08:13:47.648Z