Date parse() method with example in JavaScript

JavaScript Date parse() method: Here, we are going to learn about the parse() method in JavaScript with example.
Submitted by IncludeHelp, on March 12, 2019

JavaScript Date parse() method

parse() method is a Date class method, it is used to parse a given date string and returns the total number of milliseconds since 01st January 1970 (midnight) to given date string.

Syntax:

    Date.parse("date string");

Examples:

    
    Function call:
    Date.parse("March 12, 2019");

    Output:
    1552329000000

JavaScript code to demonstrate an example of Date.parse() method

<html>
<head><title>JavaScipt Example</title></head>

<body>
<script>
	//till 12 march
	var ms1 = Date.parse("March 12, 2019");
	document.write("ms1 = " + ms1 + "<br>");
	
	//till 13 march
	var ms2 = Date.parse("03/13/2019");
	document.write("ms2 = " + ms2 + "<br>");	
</script>
</body>
</html>

Output

ms1 = 1552329000000
ms2 = 1552415400000

Reference: JavaScript Date parse() Method

JavaScript Date Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.