Skip to content
Advertisement

How to format JavaScript date to mm/dd/yyyy?

Im getting the date like ‘Wed Nov 08 2017 00:00:00 GMT-0800 (Pacific Standard Time)’ and putting the value in an input.

Is there a way to parse the datetime into a date, add five days to it, and then format it like mm/dd/yyyy?

I made a https://jsfiddle.net/ax6qqw0t/

<script>
  startingDate = new Date(5/5/2017);
 var adjustedDate = addDays(startingDate,13);
$('#max_products').val(adjustedDate);
</script>

Advertisement

Answer

var date = new Date('Mon Aug 14 2017 00:00:00 GMT-0500 (CDT)');
var newdate= (date.getMonth() + 1) + '/' + date.getDate() + '/' +  date.getFullYear();
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement