Found 6710 Articles for Javascript

How to create JavaScript Date object from date string?

Nitya Raut
Updated on 18-Jun-2020 12:13:04

293 Views

To create a date object from date string, just add the string like this −var date = new Date(2018,1,1);ExampleYou can try to run the following code to create date object from date string. Here, the month is indexed as 0 for Jan, 1 for Feb, etc in JavaScript −Live Demo           JavaScript Dates                        var date;          date = new Date(2018,0,1);          document.write("Current Date: "+date);           OutputCurrent Date: Mon Jan 01 2018 00:00:00 GMT+0530 (India Standard Time)

How to convert epoch Date to meaningful JavaScript date?

Shubham Vora
Updated on 17-Aug-2022 12:17:47

19K+ Views

In this tutorial, we will learn to convert the epoch Date to a meaningful JavaScript date. The epoch date is a representation of the date in milliseconds, and it is a total number of milliseconds since 1st January 1970 since the UNIX epochs started. Users can convert the total number of milliseconds into the meaningful date string using various approaches explained below. Using the new Date() Object In this approach, we will create the object of the Date class. The constructor of the Date() class takes the total number of milliseconds since the epoch started and converts it into the ... Read More

How do you Convert a String to a Character Array in JavaScript?

Shubham Vora
Updated on 21-Nov-2024 18:24:57

7K+ Views

To convert a string to character array in JavaScript, is useful when you want to iterate over each charater of the string. It can be used for character manipulation like changing specific character of string. We will be understanding five different approaches for converting a string to character array. In this article we are having a string value and our task is to convert a string to character array in JavaScript. Approaches to Convert String to Character Array Here is a list of approaches to convert a string to character array in JavaScript which we will be discussing in this ... Read More

How can I get days since epoch in JavaScript?

Sravani Alamanda
Updated on 08-Dec-2022 09:30:29

4K+ Views

In this tutorial, we are going to learn about how to calculate days from epoch using JavaScript. Here, we are going to use the Math.abs() and the Math.floor() methods to calculate days. First, we are going to learn about what an epoch is. What is Epoch? It is also referred to as epoch time or Unix time or Posix time. In a determining context, an epoch is the data and time relative to which a computer's clock and timestamps are determined. An epoch time is the number of seconds that have elapsed since Jan 1st, 1970 at midnight ... Read More

How can I get time and date since epoch in JavaScript?

Shubham Vora
Updated on 17-Aug-2022 12:36:50

5K+ Views

In this tutorial, we will learn to get the date and time since epoch in JavaScript. Sometimes, programmers need to find the total number of milliseconds, seconds, days, or other things from 1 January 1970 since the UNIX epochs started. So, users can use the Date() class of JavaScript or the Moment.js library of JavaScript to get the date and time since the epoch started. Using the Object of Date() Class In this approach, we will learn to get the current date from the UNIX epoch that has been started on 1 January 1970. In JavaScript, the Date() class contains ... Read More

How to count JavaScript array objects?

Shubham Vora
Updated on 31-Oct-2023 03:09:02

26K+ Views

In this tutorial, we will learn to count JavaScript array objects. The array is the data structure containing the strings, numbers, objects, etc., in JavaScript. The object is the one kind of entity that contains properties and methods related to it. We can access the object's properties and invoke the object method using the object's references. Generally, To find the array length, we can use the array.length() method and it returns the total number of elements that the array includes. But what if we need to count only object elements? Here, this tutorial has various approaches to counting the total ... Read More

How to clone a Date object in JavaScript?

Shubham Vora
Updated on 17-Aug-2022 08:07:27

3K+ Views

In this tutorial, we will learn to clone a Date object in JavaScript. We can create a new object of the Date class that contains the date and time according to the user’s requirement. Sometimes, it needs to copy the date, which means cloning it. In such cases, users can use the different approaches given below. Also, we will learn to set the new time and date in the cloned date in this tutorial. Clone a Date using the Date.getTime() Method Users can simply create the new object of the Date class and get the total number of milliseconds from ... Read More

How to subtract days from a date in JavaScript?

Abhishek
Updated on 04-Oct-2023 12:55:19

37K+ Views

In this tutorial, we will learn how to subtract days from a date in JavaScript. To subtract days from a JavaScript Date object, use the setDate() method. Under that, get the current days and subtract days. JavaScript date setDate() method sets the day of the month for a specified date according to local time. Following are the methods we can use to subtract days from a date in JavaScript − Using the setTime() and getTime() methods Using the setDate() and getDate() methods ... Read More

How to add 10 seconds to a JavaScript date object?

Saurabh Jaiswal
Updated on 22-Aug-2022 08:08:54

4K+ Views

In this tutorial, we will learn how to add 10 seconds to a JavaScript Date object. Here we will discuss two methods which are following. Using the setSeconds( ) Method Using the getTime() Method Using the setSeconds() Method JavaScript date setSeconds() method sets the seconds for a specified date according to local time. This method takes two arguments, the first is the number of seconds between 0 to 59 and the second is the number of milliseconds between 0 to 999. If you do not specify the second parameter, the value returned from the getMilliseconds() method is used. ... Read More

How to compare two dates with JavaScript?

Shubham Vora
Updated on 17-Aug-2022 08:14:16

19K+ Views

In this tutorial, we will learn to compare two dates with JavaScript. The date is also one of the data types in JavaScript, and most developer works with it while developing applications. Let’s understand the need to compare the date with a real-life example. Most of you are using the internet data, and the company sends a message like “2 days left for your data pack validity.” Also, users can see the same notification in the application of network provides. This all happens due to the date comparison. Here, we have two various approaches to make a comparison between the ... Read More

Advertisements