JavaScript Date valueOf() method - JavaScript Tutorial

JavaScript Date valueOf() method

BLUF: This tutorial on JavaScript Date valueOf() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Date valueOf() method

Understanding JavaScript Date valueOf() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The valueOf method in JavaScript for Date objects retrieves the primitive value associated with a Date instance.

Syntax

The syntax for the valueOf method is illustrated as follows:

Example

dateObj.valueOf()

Return

A primitive value of a Date object.

JavaScript Date valueOf method example

In this section, we will explore the valueOf method by examining a range of examples.

Example 1

Let us examine an instance of retrieving the primitive value from a Date object.

Example

<script>

var date=new Date();

document.writeln(date.valueOf());

</script>

Output:

Output

1533815687148

Example 2

Let’s examine an example that retrieves the primitive value from a given Date object.

Example

<script>

var date=new Date("August 15, 1947 20:22:10 GMT+0530 (India Standard Time) ");

document.writeln(date.valueOf());

</script>

Output:

Output

-706266470000

Example 3

Let us examine an additional example to retrieve the primitive value of a designated Date object.

Example

<script>

var date=new Date(2018, 7, 15, 20, 22, 10);

document.writeln(date.valueOf());

</script>

Output:

Output

1534344730000

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience