ItSolutionStuff.com

Jquery Moment Convert String to Date Example

By Hardik Savani • January 2, 2021
jQuery

Hello all! In this article, we will talk about jquery moment convert string to date. We will use moment js convert string to date. We will look at example of moment js convert string to date dd/mm/yyyy. Here you will learn moment js convert string to date format.

Here, i will give you simple example of jquery moment js toDate() method for getting date and you can easily convert string into date.

let's see both example with output:

Example

<!DOCTYPE html>

<html>

<head>

<title>jquery moment convert string to date - ItSolutionStuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" crossorigin="anonymous"></script>

</head>

<body>

<h1>jquery moment convert string to date - ItSolutionStuff.com</h1>

</body>

<script type="text/javascript">

var startDateTime = '26-12-2020'

var newDateTime = moment(startDateTime, "DD-MM-YYYY")

.toDate();

console.log(newDateTime);

</script>

<script type="text/javascript">

var startDateTime = '26-12-2020'

var newDateTime = moment(startDateTime, "DD-MM-YYYY")

.format('MM/DD/YYYY');

console.log(newDateTime);

</script>

</html>

Output:

Sat Dec 26 2020 00:00:00 GMT+0530 (India Standard Time)

12/26/2020

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

JQuery Moment JS Subtract Hours to Datetime Example

Read Now →

JQuery Moment Add Hours to Datetime Example

Read Now →

JQuery Moment Add Minutes to Datetime Example

Read Now →

JQuery Moment Add Year to Date Example

Read Now →

JQuery Moment Add Days to Date Example

Read Now →

JQuery Moment Get Current Date Example

Read Now →

How to Install and Use Moment JS in Laravel?

Read Now →

How to Change Date Format using Moment in Vue JS?

Read Now →

How to Change Date Format in JQuery?

Read Now →